refactoring mapper
This commit is contained in:
parent
9f0c7ca0ba
commit
0c5eb1d559
|
|
@ -105,10 +105,8 @@ public class DeviceRegistrationViewModel
|
|||
var result = dataSource.fetchCustomerDevice(localStorageClient.getLoggedInUser(), serialnumber);
|
||||
if (result instanceof Result.Success) {
|
||||
var successResult = ((Result.Success<DeviceArticleDto>) result).getData();
|
||||
CustomerDevice item = new CustomerDevice();
|
||||
item.setSerialNumber(successResult.getSerialnumber());
|
||||
item.setDeviceNumber(successResult.getDevice().getDeviceNumber());
|
||||
item.setName(successResult.getDevice().getName());
|
||||
|
||||
var item = getModelMapper().mapDeviceArticleFromDto(successResult);
|
||||
|
||||
|
||||
getMCustomerDevice().postValue(item);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@ public abstract class AbstractBaseViewModel extends ViewModel {
|
|||
protected final LocalStorageClient localStorageClient;
|
||||
protected Context context;
|
||||
|
||||
protected ModelMapper getModelMapper()
|
||||
{
|
||||
return ModelMapper.getInstance();
|
||||
}
|
||||
|
||||
protected ExecutorService executorService = Executors.newFixedThreadPool(4);
|
||||
|
||||
protected AbstractBaseViewModel(LocalStorageClient localStorage) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package eu.csc.vehown.ui.viewmodels;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceArticleDto;
|
||||
import eu.csc.vehown.data.model.CustomerDevice;
|
||||
import eu.csc.vehown.data.model.LoggedInUser;
|
||||
|
||||
public class ModelMapper {
|
||||
|
||||
private static ModelMapper instance;
|
||||
public static ModelMapper getInstance(){
|
||||
if(instance == null){
|
||||
instance = new ModelMapper();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public LoggedInUser mapFromDto(){
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
public CustomerDevice mapDeviceArticleFromDto(DeviceArticleDto successResult) {
|
||||
CustomerDevice item = new CustomerDevice();
|
||||
|
||||
item.setSerialNumber(successResult.getSerialnumber());
|
||||
item.setDeviceNumber(successResult.getDevice().getDeviceNumber());
|
||||
item.setName(successResult.getDevice().getName());
|
||||
item.setManufacture(successResult.getDevice().getManufacturer());
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package eu.csc.vehown.mapper;
|
||||
|
||||
import eu.csc.vehown.data.model.CustomerDevice;
|
||||
import eu.csc.vehown.data.model.LoggedInUser;
|
||||
|
||||
public class ModelMapper {
|
||||
|
||||
private static ModelMapper getInstance(){
|
||||
return new ModelMapper();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public LoggedInUser mapFromDto(){
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue