use of org.geosdi.geoplatform.exception.IllegalParameterFault in project geo-platform by geosdi.
the class GPProjectDelegate method importProject.
@Override
public Long importProject(ImportProjectRequest impRequest) throws Exception {
if (impRequest == null) {
throw new IllegalParameterFault("The ImportProjectRequest must " + "not be null.");
}
Long accountID = impRequest.getAccountID();
ProjectDTO projectDTO = impRequest.getProjectDTO();
GPAccount account = this.getAccountByID(accountID);
// TODO assert
EntityCorrectness.checkAccountLog(account);
GPProject project = ProjectDTO.convertToGPProject(projectDTO);
projectDao.persist(project);
List<FolderDTO> rootFolders = projectDTO.getRootFolders();
if (rootFolders == null) {
// TODO assert
throw new IllegalParameterFault("Project have not root folders");
}
int numberOfElements = 0;
position = 0;
for (int i = rootFolders.size() - 1; i >= 0; i--) {
FolderDTO folderDTO = rootFolders.get(i);
GPFolder folder = convertToGPFolder(project, null, folderDTO);
List<AbstractElementDTO> childs = folderDTO.getElementList();
int numberOfDescendants = this.persistElementList(project, folder, childs);
logger.trace("\n\n*** Folder {} - Desc = {} ***\n\n", folder.getName(), numberOfDescendants);
folder.setNumberOfDescendants(numberOfDescendants);
folder.setPosition(++position);
logger.trace("*** Folder {} - pos = {}", folder.getName(), folder.getPosition());
// TODO assert
EntityCorrectness.checkFolder(folder);
folderDao.persist(folder);
numberOfElements += numberOfDescendants + 1;
}
logger.trace("\n\n *** numberOfElements = {} ***\n\n", numberOfElements);
project.setNumberOfElements(numberOfElements);
// TODO assert
EntityCorrectness.checkProject(project);
projectDao.update(project);
GPAccountProject accountProject = new GPAccountProject();
accountProject.setAccountAndProject(account, project);
accountProjectDao.persist(accountProject);
return project.getId();
}
use of org.geosdi.geoplatform.exception.IllegalParameterFault in project geo-platform by geosdi.
the class GPProjectDelegate method cloneProject.
@Override
public Long cloneProject(CloneProjectRequest cloneProjectRequest) throws Exception {
GPAccount gpAccount = accountDao.find(cloneProjectRequest.getAccountID());
if (gpAccount == null) {
throw new ResourceNotFoundFault("Account not found for with id:\"" + cloneProjectRequest.getAccountID());
}
GPProject gpProject = projectDao.find(cloneProjectRequest.getGpProjectID());
if (gpProject == null) {
throw new ResourceNotFoundFault("Project not found for with id:\"" + cloneProjectRequest.getGpProjectID());
}
gpProject.setShared(false);
try {
// Root Folders
List<GPFolder> rootFolders = folderDao.searchRootFolders(cloneProjectRequest.getGpProjectID());
logger.debug("\n*** rootFolders:\n{}", rootFolders);
GPProject projectCloned = newGProjectBinder().withNameProject(cloneProjectRequest.getNameProject()).withFrom(gpProject).bind();
GPAccountProject gpAccountProject = new GPAccountProject();
gpAccountProject.setAccount(gpAccount);
gpAccountProject.setProject(projectCloned);
gpAccountProject.setDefaultProject(false);
projectDao.persist(projectCloned);
accountProjectDao.persist(gpAccountProject);
Map<Long, GPFolder> folderMap = IntStream.iterate(0, n -> n + 1).limit(rootFolders.size()).boxed().collect(Collectors.toMap(i -> rootFolders.get(i).getId(), i -> new GPFolderFunction(projectCloned, folderDao, null).apply(rootFolders.get(i))));
// Sub Folders
List<GPFolder> subFolders = folderDao.searchSubFoders(cloneProjectRequest.getGpProjectID());
Collections.sort(subFolders, Comparator.comparingInt(f -> f.getLevel()));
IntStream.iterate(0, n -> n + 1).limit(subFolders.size()).boxed().forEach(i -> {
GPFolder folderCloned = new GPFolderFunction(projectCloned, folderDao, folderMap.get(subFolders.get(i).getParent().getId())).apply(subFolders.get(i));
folderMap.put(subFolders.get(i).getId(), folderCloned);
});
// Sub Layers
List<GPLayer> subLayers = layerDao.searchLayersByProjectID(cloneProjectRequest.getGpProjectID());
IntStream.iterate(0, n -> n + 1).limit(subLayers.size()).boxed().forEach(i -> {
new GPLayerFunction(projectCloned, layerDao, folderMap.get(subLayers.get(i).getFolder().getId())).apply(subLayers.get(i));
});
return projectCloned.getId();
} catch (IllegalParameterFault e) {
throw new IllegalParameterFault(e.getMessage());
}
}
use of org.geosdi.geoplatform.exception.IllegalParameterFault in project geo-platform by geosdi.
the class GPPublisherBasicServiceImpl method updateLayerStyle.
@Override
public Boolean updateLayerStyle(String workspace, String layerName, String styleToPublish, String styleName, boolean isDefault, boolean override) throws ResourceNotFoundFault {
GeoserverLayer geoserverLayer = null;
if (!this.checkIfExsistLayerInWorkspace(layerName, workspace)) {
throw new ResourceNotFoundFault("The layer: " + layerName + " with workspace: " + workspace + " does not exists");
}
try {
geoserverLayer = this.geoserverConnectorStore.loadWorkspaceLayerRequest().withLayerName(layerName).withWorkspaceName(workspace).getResponse();
} catch (Exception e) {
final String error = "Error to load layer with workspace name: " + workspace + " and layer name:" + layerName + " " + e;
logger.error(error);
throw new IllegalArgumentException(error, e.getCause());
}
try {
this.geoserverConnectorStore.createStyleSLDV100Request().withRaw(!override).withStyleName(styleName).withStringStyleBody(styleToPublish).getResponse();
} catch (Exception e) {
throw new IllegalParameterFault("The Style with name " + styleName + " is not published.");
}
GeoserverLayerStyle layerStyle = geoserverLayer.getLayerStyle() != null ? geoserverLayer.getLayerStyle() : new GeoserverLayerStyle();
List<IGPGeoserverStyle> styles = layerStyle.getStyles() != null ? geoserverLayer.getLayerStyle().getStyles() : Lists.newArrayList();
GPGeoserverStyle gpGeoserverStyle = new GPGeoserverStyle();
gpGeoserverStyle.setName(styleName);
if (isDefault) {
geoserverLayer.setDefaultStyle(gpGeoserverStyle);
} else {
styles.add(gpGeoserverStyle);
}
layerStyle.setStyles(styles);
geoserverLayer.setLayerStyle(layerStyle);
try {
this.geoserverConnectorStore.updateLayerRequest().withWorkspaceName(workspace).withLayerBody(geoserverLayer).withLayerName(layerName).getResponse();
} catch (Exception e) {
final String error = "Error to update layer with workspace name: " + e;
logger.error(error);
return FALSE;
}
return TRUE;
}
use of org.geosdi.geoplatform.exception.IllegalParameterFault in project geo-platform by geosdi.
the class SaveAddedLayersAndTreeModificationsCommand method execute.
@Override
public SaveAddedLayersAndTreeModificationsResponse execute(SaveAddedLayersAndTreeModificationsRequest request, HttpServletRequest httpServletRequest) {
logger.info("##################### Executing {} Command", this.getClass().getSimpleName());
try {
this.sessionUtility.getLoggedAccount(httpServletRequest);
} catch (GPSessionTimeout timeout) {
throw new GeoPlatformException(timeout);
}
List<GPLayer> layersList = this.dtoMementoConverter.convertMementoLayers(request.getMementoSaveAddedLayers().getAddedLayers());
GPWebServiceMapData map = this.dtoMementoConverter.convertDescendantMap(request.getMementoSaveAddedLayers().getWsDescendantMap());
ArrayList<Long> idSavedLayers = null;
try {
Long projectId = this.sessionUtility.getDefaultProject(httpServletRequest);
Long parentFolderId = layersList.get(0).getFolder().getId();
idSavedLayers = (ArrayList<Long>) this.geoPlatformServiceClient.saveAddedLayersAndTreeModifications(new WSAddLayersAndTreeModificationsRequest(projectId, parentFolderId, layersList, map)).getElements();
} catch (ResourceNotFoundFault | IllegalParameterFault ex) {
logger.error("Failed to save layers on LayerService: " + ex);
throw new GeoPlatformException(ex);
} catch (GPSessionTimeout timeout) {
throw new GeoPlatformException(timeout);
}
logger.debug("#################### After sending project notification");
return new SaveAddedLayersAndTreeModificationsResponse(idSavedLayers);
}
use of org.geosdi.geoplatform.exception.IllegalParameterFault in project geo-platform by geosdi.
the class SaveLayerPropertiesCommand method execute.
@Override
public SaveLayerPropertiesResponse execute(SaveLayerPropertiesRequest request, HttpServletRequest httpServletRequest) {
logger.info("##################### Executing {} Command", this.getClass().getSimpleName());
boolean result;
try {
this.sessionUtility.getLoggedAccount(httpServletRequest);
} catch (GPSessionTimeout timeout) {
throw new GeoPlatformException(timeout);
}
MementoLayerOriginalProperties mementoLayerOriginalProperties = request.getMementoLayerOriginalProperties();
RasterPropertiesDTO dto = this.dtoMementoConverter.convertMementoProperties(mementoLayerOriginalProperties);
try {
result = geoPlatformServiceClient.saveLayerProperties(dto);
} catch (ResourceNotFoundFault ex) {
SaveLayerPropertiesCommand.logger.error("Failed to save layers on LayerService: " + ex);
throw new GeoPlatformException(ex);
} catch (IllegalParameterFault ex) {
SaveLayerPropertiesCommand.logger.error("Failed to save layers on LayerService: " + ex);
throw new GeoPlatformException(ex);
}
logger.debug("#################### After sending project notification");
return new SaveLayerPropertiesResponse(result);
}
Aggregations