Search in sources :

Example 21 with IllegalParameterFault

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();
}
Also used : FolderDTO.convertToGPFolder(org.geosdi.geoplatform.response.FolderDTO.convertToGPFolder) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault)

Example 22 with IllegalParameterFault

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());
    }
}
Also used : GPLayerFunction(org.geosdi.geoplatform.core.delegate.impl.project.function.GPLayerFunction) IntStream(java.util.stream.IntStream) java.util(java.util) EntityCorrectness(org.geosdi.geoplatform.services.development.EntityCorrectness) org.geosdi.geoplatform.response(org.geosdi.geoplatform.response) PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CloneProjectRequest(org.geosdi.geoplatform.request.project.CloneProjectRequest) AccountDTOFactory.buildShortAccountDTOList(org.geosdi.geoplatform.response.factory.AccountDTOFactory.buildShortAccountDTOList) Lists(com.google.common.collect.Lists) GPFolderFunction(org.geosdi.geoplatform.core.delegate.impl.project.function.GPFolderFunction) BasePermission(org.springframework.security.acls.domain.BasePermission) ProjectDTO.convertToProjectDTOList(org.geosdi.geoplatform.response.ProjectDTO.convertToProjectDTOList) SaveProjectRequest(org.geosdi.geoplatform.request.project.SaveProjectRequest) PaginatedSearchRequest(org.geosdi.geoplatform.request.PaginatedSearchRequest) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) org.geosdi.geoplatform.core.dao(org.geosdi.geoplatform.core.dao) VectorLayerDTO.convertToGPVectorLayer(org.geosdi.geoplatform.response.VectorLayerDTO.convertToGPVectorLayer) Logger(org.slf4j.Logger) ImportProjectRequest(org.geosdi.geoplatform.request.project.ImportProjectRequest) RasterLayerDTO.convertToGPRasterLayer(org.geosdi.geoplatform.response.RasterLayerDTO.convertToGPRasterLayer) ProjectDelegate(org.geosdi.geoplatform.core.delegate.api.project.ProjectDelegate) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPProjectBinder.newGProjectBinder(org.geosdi.geoplatform.core.binding.IGPProjectBinder.GPProjectBinder.newGProjectBinder) Collectors(java.util.stream.Collectors) org.geosdi.geoplatform.core.model(org.geosdi.geoplatform.core.model) Component(org.springframework.stereotype.Component) SearchRequest(org.geosdi.geoplatform.request.SearchRequest) TRUE(java.lang.Boolean.TRUE) RequestByAccountProjectIDs(org.geosdi.geoplatform.request.RequestByAccountProjectIDs) FolderDTO.convertToGPFolder(org.geosdi.geoplatform.response.FolderDTO.convertToGPFolder) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) FolderDTO.convertToGPFolder(org.geosdi.geoplatform.response.FolderDTO.convertToGPFolder) GPFolderFunction(org.geosdi.geoplatform.core.delegate.impl.project.function.GPFolderFunction) GPLayerFunction(org.geosdi.geoplatform.core.delegate.impl.project.function.GPLayerFunction)

Example 23 with IllegalParameterFault

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;
}
Also used : GeoserverLayerStyle(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayerStyle) GeoserverLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle) GPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) FactoryException(org.opengis.referencing.FactoryException) DataSourceException(org.geotools.data.DataSourceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle)

Example 24 with IllegalParameterFault

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);
}
Also used : WSAddLayersAndTreeModificationsRequest(org.geosdi.geoplatform.request.layer.WSAddLayersAndTreeModificationsRequest) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) GPLayer(org.geosdi.geoplatform.core.model.GPLayer) GPWebServiceMapData(org.geosdi.geoplatform.response.collection.GPWebServiceMapData) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPSessionTimeout(org.geosdi.geoplatform.gui.utility.GPSessionTimeout) SaveAddedLayersAndTreeModificationsResponse(org.geosdi.geoplatform.gui.client.command.memento.basic.SaveAddedLayersAndTreeModificationsResponse) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException)

Example 25 with IllegalParameterFault

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);
}
Also used : IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) RasterPropertiesDTO(org.geosdi.geoplatform.response.RasterPropertiesDTO) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPSessionTimeout(org.geosdi.geoplatform.gui.utility.GPSessionTimeout) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException) MementoLayerOriginalProperties(org.geosdi.geoplatform.gui.client.model.memento.save.storage.MementoLayerOriginalProperties) SaveLayerPropertiesResponse(org.geosdi.geoplatform.gui.client.command.memento.basic.SaveLayerPropertiesResponse)

Aggregations

IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)56 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)32 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)22 GPSessionTimeout (org.geosdi.geoplatform.gui.utility.GPSessionTimeout)15 GPWebServiceMapData (org.geosdi.geoplatform.response.collection.GPWebServiceMapData)11 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 GPFolder (org.geosdi.geoplatform.core.model.GPFolder)7 GPUser (org.geosdi.geoplatform.core.model.GPUser)7 GPOrganization (org.geosdi.geoplatform.core.model.GPOrganization)6 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)5 GPAccountProject (org.geosdi.geoplatform.core.model.GPAccountProject)4 Test (org.junit.Test)4 URL (java.net.URL)3 InsertAccountRequest (org.geosdi.geoplatform.request.InsertAccountRequest)3 BasePagingLoadResult (com.extjs.gxt.ui.client.data.BasePagingLoadResult)2 GPCSWConnectorBuilder (org.geosdi.geoplatform.connector.GPCSWConnectorBuilder)2 GPCatalogConnectorStore (org.geosdi.geoplatform.connector.GPCatalogConnectorStore)2 BasicPreemptiveSecurityConnector (org.geosdi.geoplatform.connector.server.security.BasicPreemptiveSecurityConnector)2 GPSecurityConnector (org.geosdi.geoplatform.connector.server.security.GPSecurityConnector)2