improved behaviour of file storage mgmt service

This commit is contained in:
Fredrik Teschke
2015-01-23 22:00:38 +01:00
parent 6c9cd3d66f
commit ed68e19251
12 changed files with 169 additions and 112 deletions
@@ -56,7 +56,7 @@ import com.sap.sailing.gwt.ui.shared.DeviceMappingDTO;
import com.sap.sailing.gwt.ui.shared.EventBaseDTO;
import com.sap.sailing.gwt.ui.shared.EventDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServiceDTO;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyErrors;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyErrors;
import com.sap.sailing.gwt.ui.shared.GPSFixDTO;
import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO;
import com.sap.sailing.gwt.ui.shared.LeaderboardSearchResultDTO;
@@ -581,15 +581,13 @@ public interface SailingService extends RemoteService {
/**
* @throws NoCorrespondingServiceRegisteredException service may have disappeared from registry in the meantime
* @return only a service with valid properties can be selected for usage
*/
FileStoragePropertyErrors testFileStorageServiceProperties(String serviceName) throws NoCorrespondingServiceRegisteredException;
FileStorageServicePropertyErrors testFileStorageServiceProperties(String serviceName) throws NoCorrespondingServiceRegisteredException;
/**
* @throws NoCorrespondingServiceRegisteredException service may have disappeared from registry in the meantime
* @return only a service with valid properties can be selected for usage
*/
FileStoragePropertyErrors setActiveFileStorageService(String serviceName) throws NoCorrespondingServiceRegisteredException;
void setActiveFileStorageService(String serviceName) throws NoCorrespondingServiceRegisteredException;
/**
* @return may be {@code null}
@@ -46,7 +46,7 @@ import com.sap.sailing.gwt.ui.shared.DeviceMappingDTO;
import com.sap.sailing.gwt.ui.shared.EventBaseDTO;
import com.sap.sailing.gwt.ui.shared.EventDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServiceDTO;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyErrors;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyErrors;
import com.sap.sailing.gwt.ui.shared.GPSFixDTO;
import com.sap.sailing.gwt.ui.shared.LeaderboardGroupDTO;
import com.sap.sailing.gwt.ui.shared.LeaderboardSearchResultDTO;
@@ -692,9 +692,9 @@ public interface SailingServiceAsync extends BuildVersionRetriever {
void getAvailableFileStorageServices(AsyncCallback<FileStorageServiceDTO[]> callback);
void testFileStorageServiceProperties(String serviceName, AsyncCallback<FileStoragePropertyErrors> callback);
void testFileStorageServiceProperties(String serviceName, AsyncCallback<FileStorageServicePropertyErrors> callback);
void setActiveFileStorageService(String serviceName, AsyncCallback<FileStoragePropertyErrors> callback);
void setActiveFileStorageService(String serviceName, AsyncCallback<Void> callback);
void getActiveFileStorageServiceName(AsyncCallback<String> callback);
@@ -28,8 +28,8 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ListDataProvider;
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyDTO;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyErrors;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyErrors;
import com.sap.sailing.gwt.ui.shared.FileStorageServiceDTO;
import com.sap.sse.gwt.client.ErrorReporter;
@@ -39,12 +39,13 @@ public class FileStoragePanel extends FlowPanel {
private final Label activeServiceLabel;
private final ListBox servicesListBox;
private CellTable<FileStoragePropertyDTO> propertiesTable;
private CellTable<FileStorageServicePropertyDTO> propertiesTable;
private final Label serviceDescriptionLabel;
private final List<FileStoragePropertyDTO> properties = new ArrayList<>();
private final List<FileStorageServicePropertyDTO> properties;
private final Map<String, FileStorageServiceDTO> availableServices = new HashMap<>();
private final Map<FileStoragePropertyDTO, String> perPropertyErros = new HashMap<>();
private final Map<FileStorageServicePropertyDTO, String> perPropertyErrors = new HashMap<>();
private final ListDataProvider<FileStorageServicePropertyDTO> propertiesListDataProvider;
public FileStoragePanel(SailingServiceAsync sailingService, ErrorReporter errorReporter,
StringMessages stringMessages) {
@@ -81,46 +82,48 @@ public class FileStoragePanel extends FlowPanel {
editServicePanelContent.add(serviceDescriptionLabel);
propertiesTable = new CellTable<>();
ListDataProvider<FileStoragePropertyDTO> propertiesListDataProvider = new ListDataProvider<>(properties);
propertiesListDataProvider = new ListDataProvider<>(new ArrayList<FileStorageServicePropertyDTO>());
properties = propertiesListDataProvider.getList();
propertiesListDataProvider.addDataDisplay(propertiesTable);
TextColumn<FileStoragePropertyDTO> nameColumn = new TextColumn<FileStoragePropertyDTO>() {
TextColumn<FileStorageServicePropertyDTO> nameColumn = new TextColumn<FileStorageServicePropertyDTO>() {
@Override
public String getValue(FileStoragePropertyDTO p) {
public String getValue(FileStorageServicePropertyDTO p) {
return p.name;
}
};
propertiesTable.addColumn(nameColumn, stringMessages.name());
Column<FileStoragePropertyDTO, String> inputColumn = new Column<FileStoragePropertyDTO, String>(new TextInputCell()) {
Column<FileStorageServicePropertyDTO, String> inputColumn = new Column<FileStorageServicePropertyDTO, String>(new TextInputCell()) {
@Override
public String getValue(FileStoragePropertyDTO object) {
public String getValue(FileStorageServicePropertyDTO object) {
return object.value;
}
};
inputColumn.setFieldUpdater(new FieldUpdater<FileStoragePropertyDTO, String>() {
inputColumn.setFieldUpdater(new FieldUpdater<FileStorageServicePropertyDTO, String>() {
@Override
public void update(int index, FileStoragePropertyDTO object, String value) {
public void update(int index, FileStorageServicePropertyDTO object, String value) {
object.value = value;
}
});
propertiesTable.addColumn(inputColumn, stringMessages.value());
TextColumn<FileStoragePropertyDTO> descriptionColumn = new TextColumn<FileStoragePropertyDTO>() {
TextColumn<FileStorageServicePropertyDTO> descriptionColumn = new TextColumn<FileStorageServicePropertyDTO>() {
@Override
public String getValue(FileStoragePropertyDTO p) {
public String getValue(FileStorageServicePropertyDTO p) {
return p.description;
}
};
propertiesTable.addColumn(descriptionColumn, stringMessages.description());
TextColumn<FileStoragePropertyDTO> errorColumn = new TextColumn<FileStoragePropertyDTO>() {
TextColumn<FileStorageServicePropertyDTO> errorColumn = new TextColumn<FileStorageServicePropertyDTO>() {
@Override
public String getValue(FileStoragePropertyDTO p) {
String error = perPropertyErros.get(p);
public String getValue(FileStorageServicePropertyDTO p) {
String error = perPropertyErrors.get(p);
return error == null ? "" : error;
}
};
errorColumn.setCellStyleNames("errorLabel");
propertiesTable.addColumn(errorColumn, stringMessages.error());
editServicePanelContent.add(propertiesTable);
@@ -137,7 +140,7 @@ public class FileStoragePanel extends FlowPanel {
buttonsPanel.add(saveAndTestPropertiesButton);
Button setAsActiveServiceButton = new Button(stringMessages.setAsActive());
saveAndTestPropertiesButton.addClickHandler(new ClickHandler() {
setAsActiveServiceButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
setAsActiveService();
@@ -148,6 +151,8 @@ public class FileStoragePanel extends FlowPanel {
editServicePanelContent.add(buttonsPanel);
add(editServicePanel);
refresh();
}
private String getSelectedServiceName() {
@@ -156,24 +161,25 @@ public class FileStoragePanel extends FlowPanel {
private void saveAndTestProperties(final Callback<Void, Void> callback) {
Map<String, String> values = new HashMap<String, String>();
for (FileStoragePropertyDTO p : properties) {
for (FileStorageServicePropertyDTO p : properties) {
values.put(p.name, p.value);
}
perPropertyErros.clear();
perPropertyErrors.clear();
sailingService.setFileStorageServiceProperties(getSelectedServiceName(), values, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
sailingService.testFileStorageServiceProperties(getSelectedServiceName(),
new AsyncCallback<FileStoragePropertyErrors>() {
new AsyncCallback<FileStorageServicePropertyErrors>() {
@Override
public void onSuccess(FileStoragePropertyErrors result) {
public void onSuccess(FileStorageServicePropertyErrors result) {
if (result != null) {
perPropertyErros.putAll(result.perPropertyMessages);
}
propertiesTable.redraw();
if (callback != null) {
callback.onSuccess(null);
perPropertyErrors.putAll(result.perPropertyMessages);
} else {
if (callback != null) {
callback.onSuccess(null);
}
}
propertiesListDataProvider.refresh();
}
@Override
@@ -194,9 +200,9 @@ public class FileStoragePanel extends FlowPanel {
saveAndTestProperties(new Callback<Void, Void>() {
@Override
public void onSuccess(Void result) {
sailingService.setActiveFileStorageService(getSelectedServiceName(), new AsyncCallback<FileStoragePropertyErrors>() {
sailingService.setActiveFileStorageService(getSelectedServiceName(), new AsyncCallback<Void>() {
@Override
public void onSuccess(FileStoragePropertyErrors result) {
public void onSuccess(Void result) {
refresh();
}
@@ -217,7 +223,7 @@ public class FileStoragePanel extends FlowPanel {
private void onServiceSelectionChanged() {
properties.clear();
perPropertyErros.clear();
perPropertyErrors.clear();
serviceDescriptionLabel.setText("");
FileStorageServiceDTO selected = availableServices.get(getSelectedServiceName());
if (selected == null) {
@@ -6,31 +6,31 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyDTO;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyErrors;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyErrors;
import com.sap.sailing.gwt.ui.shared.FileStorageServiceDTO;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.InvalidPropertiesException;
import com.sap.sse.filestorage.Property;
public class FileStorageServiceDTOUtils {
public static FileStoragePropertyDTO convert(Property p) {
return new FileStoragePropertyDTO(p.isRequired(), p.getName(), p.getValue(), p.getDescription());
public static FileStorageServicePropertyDTO convert(Property p) {
return new FileStorageServicePropertyDTO(p.isRequired(), p.getName(), p.getValue(), p.getDescription());
}
public static FileStoragePropertyErrors convert(InvalidPropertiesException e) {
Map<FileStoragePropertyDTO, String> msgs = new HashMap<>();
public static FileStorageServicePropertyErrors convert(InvalidPropertiesException e) {
Map<FileStorageServicePropertyDTO, String> msgs = new HashMap<>();
for (Entry<Property, String> entry : e.getPerPropertyMessage().entrySet()) {
msgs.put(convert(entry.getKey()), entry.getValue());
}
return new FileStoragePropertyErrors(e.getMessage(), msgs);
return new FileStorageServicePropertyErrors(e.getMessage(), msgs);
}
public static FileStorageServiceDTO convert(FileStorageService s) {
List<FileStoragePropertyDTO> pDtos = new ArrayList<>();
List<FileStorageServicePropertyDTO> pDtos = new ArrayList<>();
for (Property p : s.getProperties()) {
pDtos.add(convert(p));
}
return new FileStorageServiceDTO(s.getName(), s.getDescription(), pDtos.toArray(new FileStoragePropertyDTO[0]));
return new FileStorageServiceDTO(s.getName(), s.getDescription(), pDtos.toArray(new FileStorageServicePropertyDTO[0]));
}
}
@@ -276,6 +276,8 @@ import com.sap.sailing.gwt.ui.shared.DeviceIdentifierDTO;
import com.sap.sailing.gwt.ui.shared.DeviceMappingDTO;
import com.sap.sailing.gwt.ui.shared.EventBaseDTO;
import com.sap.sailing.gwt.ui.shared.EventDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServiceDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServicePropertyErrors;
import com.sap.sailing.gwt.ui.shared.GPSFixDTO;
import com.sap.sailing.gwt.ui.shared.GateDTO;
import com.sap.sailing.gwt.ui.shared.LeaderboardGroupBaseDTO;
@@ -305,8 +307,6 @@ import com.sap.sailing.gwt.ui.shared.RegattaDTO;
import com.sap.sailing.gwt.ui.shared.RegattaOverviewEntryDTO;
import com.sap.sailing.gwt.ui.shared.RegattaScoreCorrectionDTO;
import com.sap.sailing.gwt.ui.shared.RegattaScoreCorrectionDTO.ScoreCorrectionEntryDTO;
import com.sap.sailing.gwt.ui.shared.FileStorageServiceDTO;
import com.sap.sailing.gwt.ui.shared.FileStoragePropertyErrors;
import com.sap.sailing.gwt.ui.shared.RemoteSailingServerReferenceDTO;
import com.sap.sailing.gwt.ui.shared.ReplicaDTO;
import com.sap.sailing.gwt.ui.shared.ReplicationMasterDTO;
@@ -5426,6 +5426,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
private FileStorageService getFileStorageService(String name) {
if (name == null || name.equals("")) {
return null;
}
return getService().getFileStorageManagementService().getFileStorageService(name);
}
@@ -5441,15 +5444,22 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
@Override
public void setFileStorageServiceProperties(String serviceName, Map<String, String> properties) {
for (Entry<String, String> p : properties.entrySet()) {
getService().getFileStorageManagementService()
.setFileStorageServiceProperty(serviceName, p.getKey(), p.getValue());
try {
getService().getFileStorageManagementService()
.setFileStorageServiceProperty(serviceName, p.getKey(), p.getValue());
} catch (NoCorrespondingServiceRegisteredException | IllegalArgumentException e) {
//ignore, doing refresh afterwards anyways
}
}
}
@Override
public FileStoragePropertyErrors testFileStorageServiceProperties(String serviceName) {
public FileStorageServicePropertyErrors testFileStorageServiceProperties(String serviceName) {
try {
getFileStorageService(serviceName).testProperties();
FileStorageService service = getFileStorageService(serviceName);
if (service != null) {
service.testProperties();
}
} catch (InvalidPropertiesException e) {
return FileStorageServiceDTOUtils.convert(e);
}
@@ -5457,17 +5467,16 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
@Override
public FileStoragePropertyErrors setActiveFileStorageService(String serviceName) {
try {
getService().getFileStorageManagementService().setActiveFileStorageService(getFileStorageService(serviceName));
} catch (InvalidPropertiesException e) {
return FileStorageServiceDTOUtils.convert(e);
}
return null;
public void setActiveFileStorageService(String serviceName) {
getService().getFileStorageManagementService().setActiveFileStorageService(getFileStorageService(serviceName));
}
@Override
public String getActiveFileStorageServiceName() {
return getService().getFileStorageManagementService().getActiveFileStorageService().getName();
try {
return getService().getFileStorageManagementService().getActiveFileStorageService().getName();
} catch (NoCorrespondingServiceRegisteredException e) {
return null;
}
}
}
@@ -1,22 +0,0 @@
package com.sap.sailing.gwt.ui.shared;
import java.io.Serializable;
public class FileStoragePropertyDTO implements Serializable {
private static final long serialVersionUID = -2721807793068803143L;
public boolean isRequired;
public String name;
public String value;
public String description;
// for GWT
FileStoragePropertyDTO() {
}
public FileStoragePropertyDTO(boolean isRequired, String name, String value, String description) {
this.isRequired = isRequired;
this.name = name;
this.value = value;
this.description = description;
}
}
@@ -1,19 +0,0 @@
package com.sap.sailing.gwt.ui.shared;
import java.io.Serializable;
import java.util.Map;
public class FileStoragePropertyErrors implements Serializable {
private static final long serialVersionUID = -7328897153875728802L;
public Map<FileStoragePropertyDTO, String> perPropertyMessages;
public String message;
// for GWT
FileStoragePropertyErrors() {
}
public FileStoragePropertyErrors(String message, Map<FileStoragePropertyDTO, String> perPropertyMessages) {
this.message = message;
this.perPropertyMessages = perPropertyMessages;
}
}
@@ -6,15 +6,40 @@ public class FileStorageServiceDTO implements Serializable {
private static final long serialVersionUID = 6101940297792100418L;
public String name;
public String description;
public FileStoragePropertyDTO[] properties;
public FileStorageServicePropertyDTO[] properties;
// for GWT
FileStorageServiceDTO() {
}
public FileStorageServiceDTO(String name, String description, FileStoragePropertyDTO... properties) {
public FileStorageServiceDTO(String name, String description, FileStorageServicePropertyDTO... properties) {
this.name = name;
this.description = description;
this.properties = properties;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FileStorageServiceDTO other = (FileStorageServiceDTO) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -0,0 +1,47 @@
package com.sap.sailing.gwt.ui.shared;
import java.io.Serializable;
public class FileStorageServicePropertyDTO implements Serializable {
private static final long serialVersionUID = -2721807793068803143L;
public boolean isRequired;
public String name;
public String value;
public String description;
// for GWT
FileStorageServicePropertyDTO() {
}
public FileStorageServicePropertyDTO(boolean isRequired, String name, String value, String description) {
this.isRequired = isRequired;
this.name = name;
this.value = value;
this.description = description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FileStorageServicePropertyDTO other = (FileStorageServicePropertyDTO) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -0,0 +1,19 @@
package com.sap.sailing.gwt.ui.shared;
import java.io.Serializable;
import java.util.Map;
public class FileStorageServicePropertyErrors implements Serializable {
private static final long serialVersionUID = -7328897153875728802L;
public Map<FileStorageServicePropertyDTO, String> perPropertyMessages;
public String message;
// for GWT
FileStorageServicePropertyErrors() {
}
public FileStorageServicePropertyErrors(String message, Map<FileStorageServicePropertyDTO, String> perPropertyMessages) {
this.message = message;
this.perPropertyMessages = perPropertyMessages;
}
}
@@ -31,10 +31,5 @@ public interface FileStorageManagementService {
*/
FileStorageService getActiveFileStorageService() throws NoCorrespondingServiceRegisteredException;
/**
* @throws InvalidPropertiesException
* if the service properties are {@link FileStorageService#testProperties() invalid}. Then the old
* active service (if any) remains active.
*/
void setActiveFileStorageService(FileStorageService service) throws InvalidPropertiesException;
void setActiveFileStorageService(FileStorageService service);
}
@@ -6,7 +6,6 @@ import com.sap.sse.common.NoCorrespondingServiceRegisteredException;
import com.sap.sse.common.TypeBasedServiceFinder;
import com.sap.sse.filestorage.FileStorageManagementService;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.InvalidPropertiesException;
import com.sap.sse.osgi.CachedOsgiTypeBasedServiceFinderFactory;
public class TransientFileStorageManagementServiceImpl implements FileStorageManagementService {
@@ -28,7 +27,7 @@ public class TransientFileStorageManagementServiceImpl implements FileStorageMan
}
@Override
public void setActiveFileStorageService(FileStorageService service) throws InvalidPropertiesException {
public void setActiveFileStorageService(FileStorageService service) {
active = service;
}