Search in sources :

Example 1 with LayerPublishAction

use of org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction in project geo-platform by geosdi.

the class GPPublisherBasicServiceImpl method getTIFURLByLayerName.

private InfoPreview getTIFURLByLayerName(String workspace, String layerName) {
    String userWorkspace = workspace;
    if (userWorkspace == null) {
        userWorkspace = this.getWorkspace(workspace);
    }
    GeoserverLayer geoserverLayer = null;
    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());
    }
    if (geoserverLayer == null) {
        throw new ResourceNotFoundFault("The layer: " + layerName + " with workspace: " + workspace + " does not exists");
    }
    if (geoserverLayer.getLayerType().getType() != GeoserverLayerType.Raster.getType()) {
        throw new ResourceNotFoundFault("Bad layer type for layer " + layerName);
    }
    InfoPreview info = null;
    try {
        GeoserverLoadCoverageWithUrlRequest gpGeoserverLoadCoverageWithUrlRequest = this.geoserverConnectorStore.loadCoverageInfoWithUrl().withUrl(geoserverLayer.getLayerResource().getHref());
        GPGeoserverCoverageInfo gpGeoserverFeatureTypeInfo = gpGeoserverLoadCoverageWithUrlRequest.getResponse();
        Integer code = this.getEPSGCodeFromString(gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getCrs());
        String epsgCode = null;
        if (code != null) {
            epsgCode = "EPSG:" + code.toString();
        }
        info = new InfoPreview(RESTURL, userWorkspace, layerName, gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMinx(), gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMiny(), gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMaxx(), gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMaxy(), epsgCode, geoserverLayer.getDefaultStyle().getName(), FALSE, Lists.<LayerPublishAction>newArrayList(LayerPublishAction.OVERRIDE, LayerPublishAction.RENAME));
    } catch (Exception e) {
        final String error = "The layer " + layerName + " is published in the " + userWorkspace + " workspace, but the server cannot provide info. " + e;
        logger.error(error);
        throw new IllegalArgumentException(error, e.getCause());
    // info = new InfoPreview(layerName,
    // "The layer " + layerName + " is published in the " + userWorkspace + " workspace, but the server cannot provide info");
    }
    return info;
}
Also used : GeoserverLoadCoverageWithUrlRequest(org.geosdi.geoplatform.connector.geoserver.request.workspaces.coverages.GeoserverLoadCoverageWithUrlRequest) GeoserverLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer) LayerPublishAction(org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPGeoserverCoverageInfo(org.geosdi.geoplatform.connector.geoserver.model.workspace.coverages.GPGeoserverCoverageInfo) FactoryException(org.opengis.referencing.FactoryException) DataSourceException(org.geotools.data.DataSourceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with LayerPublishAction

use of org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction in project geo-platform by geosdi.

the class PublishUtility method renameZipShp.

private static boolean renameZipShp(String userName, InfoPreview infoPreview, String tempUserDir) throws ResourceNotFoundFault {
    String tempUserZipDir = PublishUtility.createDir(tempUserDir + PublishUtility.ZIP_DIR_NAME);
    boolean result = false;
    LayerPublishAction layerPublishAction = infoPreview.getLayerPublishAction();
    String newName = userName + "_shp_" + infoPreview.getNewName();
    if (layerPublishAction != null && layerPublishAction.equals(LayerPublishAction.RENAME) && newName != null && !newName.equalsIgnoreCase(infoPreview.getDataStoreName())) {
        String fileName = tempUserZipDir + infoPreview.getDataStoreName() + ".zip";
        File previousFile = new File(fileName);
        ZipFile zipSrc = null;
        String renameDirPath = tempUserZipDir + "rename" + System.getProperty("file.separator");
        try {
            PublishUtility.createDir(renameDirPath);
            logger.debug("********* ManageRename renameDirPath: " + renameDirPath);
            // Decomprime il contenuto dello zip nella cartella rename
            zipSrc = new ZipFile(previousFile);
            Enumeration<? extends ZipEntry> entries = zipSrc.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                PublishUtility.extractEntryToFile(entry, zipSrc, renameDirPath);
            }
            logger.debug("********* ManageRename element unzipped");
            // Dopo l'estrazione rinominare e creare zip
            compressFiles(tempUserZipDir, renameDirPath, newName + ".zip", infoPreview.getDataStoreName(), newName);
            logger.debug("********* ManageRename after compress file");
            // Cancellare vecchio zip
            previousFile.delete();
            logger.debug("********* ManageRename after delete previous file");
            result = Boolean.TRUE;
        } catch (Exception e) {
            logger.error("ERRORE : " + e);
            throw new ResourceNotFoundFault(e.getMessage());
        } finally {
            try {
                zipSrc.close();
                // Cancella cartella rename
                PublishUtility.deleteDir(renameDirPath);
                logger.debug("********* ManageRename succesfully removed rename dir");
            } catch (IOException ex) {
            }
        }
        logger.debug("Shape Zip renamed: " + result);
        if (result) {
            infoPreview.setDataStoreName(newName);
        }
    }
    return result;
}
Also used : ZipFile(java.util.zip.ZipFile) LayerPublishAction(org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction) ZipEntry(java.util.zip.ZipEntry) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) ZipFile(java.util.zip.ZipFile)

Example 3 with LayerPublishAction

use of org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction in project geo-platform by geosdi.

the class PublishUtility method renameTif.

private static boolean renameTif(String userName, InfoPreview infoPreview, String tempUserDir) throws ResourceNotFoundFault {
    boolean result = false;
    String tempUserTifDir = PublishUtility.createDir(tempUserDir + PublishUtility.TIF_DIR_NAME);
    LayerPublishAction layerPublishAction = infoPreview.getLayerPublishAction();
    String newName = userName + "_" + infoPreview.getNewName();
    if (layerPublishAction != null && layerPublishAction.equals(LayerPublishAction.RENAME) && newName != null && !newName.equalsIgnoreCase(infoPreview.getDataStoreName())) {
    // Rinominare il file nuovo con il nuovo nome
    } else if (layerPublishAction != null && layerPublishAction.equals(LayerPublishAction.OVERRIDE)) {
        // Cancellare il vecchio file e rinominare il file nuovo con il vecchio nome
        logger.debug("renameTif in Override operation");
        String fileName = tempUserTifDir + infoPreview.getDataStoreName() + ".tif";
        File previousFile = new File(fileName);
        previousFile.delete();
        newName = infoPreview.getDataStoreName();
        logger.debug("renameTif after Override operation: " + newName);
    }
    String origName = infoPreview.getFileName();
    String fileName = tempUserTifDir + origName + ".tif";
    File previousFile = new File(fileName);
    previousFile.renameTo(new File(tempUserTifDir + newName + ".tif"));
    // 
    String SLDFileName = origName + ".sld";
    File fileSLD = new File(tempUserTifDir, SLDFileName);
    if (fileSLD.exists()) {
        File filePublished = PublishUtility.copyFile(fileSLD, tempUserTifDir, newName + ".sld", true);
        fileSLD.delete();
    }
    // 
    String TFWFileName = origName + ".tfw";
    File fileTFW = new File(tempUserTifDir, TFWFileName);
    if (fileTFW.exists()) {
        PublishUtility.copyFile(fileTFW, tempUserTifDir, newName + ".tfw", true);
        fileTFW.delete();
    }
    String PRJFileName = origName + ".prj";
    File filePRJ = new File(tempUserTifDir, PRJFileName);
    if (filePRJ.exists()) {
        PublishUtility.copyFile(filePRJ, tempUserTifDir, newName + ".prj", true);
        filePRJ.delete();
    }
    infoPreview.setDataStoreName(newName);
    result = Boolean.TRUE;
    logger.debug("Tif renamed: " + result);
    return result;
}
Also used : LayerPublishAction(org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction) ZipFile(java.util.zip.ZipFile)

Example 4 with LayerPublishAction

use of org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction in project geo-platform by geosdi.

the class GPPublisherBasicServiceImpl method buildSHPInfoPreviewFromExistingWK.

/**
 * *****************************
 *
 * @param workspace the wk to use
 * @param layerName the layerName to retrieve
 * @param styleName the style name to set or if null will be setted the
 *                  default one
 * @return the builded InfoPreview
 * @throws ResourceNotFoundFault
 */
private InfoPreview buildSHPInfoPreviewFromExistingWK(String workspace, String layerName, String styleName) throws ResourceNotFoundFault, IllegalArgumentException {
    String userWorkspace = workspace;
    if (userWorkspace == null) {
        userWorkspace = this.getWorkspace(workspace);
    }
    GeoserverLayer geoserverLayer = null;
    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());
    }
    GeoserverLoadFeatureTypeWithUrlRequest geoserverLoadFeatureTypeWithUrlRequest = this.geoserverConnectorStore.loadFeatureTypeWithUrl().withUrl(geoserverLayer.getLayerResource().getHref());
    InfoPreview infoPreview = null;
    try {
        GPGeoserverFeatureTypeInfo gpGeoserverFeatureTypeInfo = geoserverLoadFeatureTypeWithUrlRequest.getResponse();
        logger.info("Parameters: userWorkspace: " + userWorkspace + " - layerName: " + layerName + " - featureType: " + gpGeoserverFeatureTypeInfo + " - layer: " + layerName + " - RESTURL: " + RESTURL);
        // Map<String, String> parametersMap = Maps.newHashMap();
        // parametersMap.put("url", layerName);
        // featureType = DataStoreFinder.getDataStore(parametersMap).getFeatureSource(layerName);
        // System.out.println("" + CRS.getGeographicBoundingBox());
        Integer code = this.getEPSGCodeFromString(gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getCrs());
        String epsgCode = null;
        if (code != null) {
            epsgCode = "EPSG:" + code.toString();
        }
        infoPreview = new InfoPreview(RESTURL, userWorkspace, layerName, gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMinx(), gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMiny(), gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMaxx(), gpGeoserverFeatureTypeInfo.getLatLonBoundingBox().getMaxy(), epsgCode, GPSharedUtils.isEmpty(styleName) ? geoserverLayer.getDefaultStyle().getName() : styleName, TRUE, Lists.<LayerPublishAction>newArrayList(LayerPublishAction.values()));
    } catch (Exception e) {
        final String error = "The layer " + layerName + " is published in the " + userWorkspace + " workspace, but the server cannot provide info. " + e;
        logger.error(error);
        throw new IllegalArgumentException(error, e.getCause());
    // info = new InfoPreview(layerName,
    // "The layer " + layerName + " is published in the " + userWorkspace + " workspace, but the server cannot provide info");
    }
    return infoPreview;
}
Also used : GeoserverLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer) GeoserverLoadFeatureTypeWithUrlRequest(org.geosdi.geoplatform.connector.geoserver.request.featuretypes.GeoserverLoadFeatureTypeWithUrlRequest) LayerPublishAction(org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction) GPGeoserverFeatureTypeInfo(org.geosdi.geoplatform.connector.geoserver.model.featuretypes.GPGeoserverFeatureTypeInfo) FactoryException(org.opengis.referencing.FactoryException) DataSourceException(org.geotools.data.DataSourceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 5 with LayerPublishAction

use of org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction in project geo-platform by geosdi.

the class EPSGTablePanel method addComponent.

@Override
public void addComponent() {
    List<ColumnConfig> configs = Lists.<ColumnConfig>newArrayList();
    ColumnConfig featureNameColumnConfig = new ColumnConfig(EPSGLayerData.NAME, PublisherWidgetConstants.INSTANCE.EPSGTablePanel_columnFeatureNameText(), 80);
    configs.add(featureNameColumnConfig);
    ColumnConfig epsgColumnConfig = new ColumnConfig(EPSGLayerData.CRS, PublisherWidgetConstants.INSTANCE.EPSGTablePanel_columnEPSGCodeText(), 80);
    GPSecureStringTextField epsgTextField = new GPSecureStringTextField();
    epsgTextField.setEmptyText(PublisherWidgetConstants.INSTANCE.EPSGTablePanel_epsgTextFieldEmptyText());
    epsgTextField.setAllowBlank(Boolean.FALSE);
    epsgColumnConfig.setEditor(new CellEditor(epsgTextField));
    configs.add(epsgColumnConfig);
    ColumnConfig newNameColumnConfig = new ColumnConfig(EPSGLayerData.NEW_NAME, PublisherWidgetConstants.INSTANCE.EPSGTablePanel_columnNewNameText(), 120);
    GPSecureStringTextField newNameTextField = new GPSecureStringTextField();
    newNameTextField.setEmptyText(PublisherWidgetConstants.INSTANCE.EPSGTablePanel_epsgTextFieldEmptyText());
    newNameTextField.setAllowBlank(Boolean.TRUE);
    final CellEditor newNameCellEditor = new CellEditor(newNameTextField);
    newNameColumnConfig.setEditor(newNameCellEditor);
    ColumnConfig publishColumnConfig = new ColumnConfig(EPSGLayerData.PUBLISH_ACTION, PublisherWidgetConstants.INSTANCE.EPSGTablePanel_columnPublishActionText(), 100);
    GridCellRenderer<EPSGLayerData> renderer = new GridCellRenderer<EPSGLayerData>() {

        @Override
        public Object render(final EPSGLayerData model, String property, ColumnData config, int rowIndex, final int colIndex, final ListStore<EPSGLayerData> store, final Grid<EPSGLayerData> grid) {
            SimpleComboBox<String> publishActionComboBox;
            Object publishActionCBObj = comboBoxMap.get("" + model.hashCode());
            if (publishActionCBObj == null) {
                publishActionComboBox = new SimpleComboBox<String>();
                publishActionComboBox.setEditable(Boolean.FALSE);
                publishActionComboBox.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 5);
                List<LayerPublishAction> l = model.getPublishActions();
                if (l != null) {
                    for (LayerPublishAction publishAction : GPSharedUtils.safeList(l)) {
                        publishActionComboBox.add(publishAction.toString());
                    }
                    publishActionComboBox.setAllowBlank(Boolean.FALSE);
                    publishActionComboBox.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

                        @Override
                        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
                            SimpleComboValue<String> selectedItem = se.getSelectedItem();
                            if (selectedItem != null) {
                                String publishAction = selectedItem.getValue();
                                model.setPublishAction(publishAction);
                                if (!LayerPublishAction.valueOf(publishAction).equals(LayerPublishAction.RENAME)) {
                                    model.setNewName("");
                                    store.update(model);
                                }
                            } else {
                                model.setPublishAction(null);
                            }
                            manageProcessEPSGButton();
                        }
                    });
                } else {
                    publishActionComboBox.setEnabled(Boolean.FALSE);
                }
                comboBoxMap.put("" + model.hashCode(), publishActionComboBox);
            } else {
                publishActionComboBox = (SimpleComboBox<String>) publishActionCBObj;
            }
            return publishActionComboBox;
        }
    };
    publishColumnConfig.setRenderer(renderer);
    configs.add(publishColumnConfig);
    configs.add(newNameColumnConfig);
    this.grid = new EditorGrid<EPSGLayerData>(store, new ColumnModel(configs));
    grid.setBorders(Boolean.TRUE);
    grid.setStripeRows(Boolean.TRUE);
    grid.setBorders(Boolean.TRUE);
    this.grid.setClicksToEdit(EditorGrid.ClicksToEdit.ONE);
    grid.setStyleAttribute("borderTop", "none");
    grid.setAutoExpandColumn(EPSGLayerData.NAME);
    grid.setAutoExpandMin(120);
    grid.setSize(GPPublisherWidget.PUBLISHER_WIDGET_WIDTH - 29, GPPublisherWidget.PUBLISHER_WIDGET_HEIGHT - 223);
    super.add(this.grid);
    this.processEPSGButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            PublisherProgressBar.getInstance().show(PublisherWidgetConstants.INSTANCE.EPSGTablePanel_processingDataProgressBarText());
            store.commitChanges();
            processEPSGRequest.setPreviewLayerList(store.getModels());
            processEPSGRequest.setWorkspace(workspace);
            ClientCommandDispatcher.getInstance().execute(new GPClientCommand<ProcessEPSGResultResponse>() {

                private static final long serialVersionUID = -8303308816796000537L;

                {
                    super.setCommandRequest(processEPSGRequest);
                }

                private FeaturePreviewEvent event = new FeaturePreviewEvent();

                @Override
                public void onCommandSuccess(ProcessEPSGResultResponse response) {
                    PublisherProgressBar.getInstance().hide();
                    event.setResult(response.getResult());
                    GPHandlerManager.fireEvent(event);
                    comboBoxMap.clear();
                }

                @Override
                public void onCommandFailure(Throwable exception) {
                    PublisherProgressBar.getInstance().hide();
                    GeoPlatformMessage.errorMessage(PublisherWidgetConstants.INSTANCE.errorPublishingText(), exception.getMessage());
                    logger.log(Level.WARNING, "EPSGTablePanel Exception: " + exception.toString());
                    logger.log(Level.WARNING, "Stack Trace Exception: " + exception.getStackTrace());
                    logger.log(Level.WARNING, "Message Exception: " + exception.getMessage());
                    exception.printStackTrace();
                }
            });
        }
    });
    this.processEPSGButton.setToolTip(PublisherWidgetConstants.INSTANCE.EPSGTablePanel_processEPSGButtonTooltipText());
    super.addButton(this.processEPSGButton);
}
Also used : GPSecureStringTextField(org.geosdi.geoplatform.gui.configuration.GPSecureStringTextField) LayerPublishAction(org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction) SimpleComboValue(com.extjs.gxt.ui.client.widget.form.SimpleComboValue) ListStore(com.extjs.gxt.ui.client.store.ListStore) EPSGLayerData(org.geosdi.geoplatform.gui.client.model.EPSGLayerData) FeaturePreviewEvent(org.geosdi.geoplatform.gui.client.event.shapepreview.FeaturePreviewEvent) GPClientCommand(org.geosdi.geoplatform.gui.command.api.GPClientCommand) ProcessEPSGResultResponse(org.geosdi.geoplatform.gui.client.command.publish.basic.ProcessEPSGResultResponse) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent)

Aggregations

LayerPublishAction (org.geosdi.geoplatform.gui.shared.publisher.LayerPublishAction)5 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ZipFile (java.util.zip.ZipFile)2 GeoserverLayer (org.geosdi.geoplatform.connector.geoserver.model.layers.GeoserverLayer)2 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)2 DataSourceException (org.geotools.data.DataSourceException)2 FactoryException (org.opengis.referencing.FactoryException)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 SimpleComboValue (com.extjs.gxt.ui.client.widget.form.SimpleComboValue)1 ZipEntry (java.util.zip.ZipEntry)1 GPGeoserverFeatureTypeInfo (org.geosdi.geoplatform.connector.geoserver.model.featuretypes.GPGeoserverFeatureTypeInfo)1 GPGeoserverCoverageInfo (org.geosdi.geoplatform.connector.geoserver.model.workspace.coverages.GPGeoserverCoverageInfo)1 GeoserverLoadFeatureTypeWithUrlRequest (org.geosdi.geoplatform.connector.geoserver.request.featuretypes.GeoserverLoadFeatureTypeWithUrlRequest)1 GeoserverLoadCoverageWithUrlRequest (org.geosdi.geoplatform.connector.geoserver.request.workspaces.coverages.GeoserverLoadCoverageWithUrlRequest)1 ProcessEPSGResultResponse (org.geosdi.geoplatform.gui.client.command.publish.basic.ProcessEPSGResultResponse)1 FeaturePreviewEvent (org.geosdi.geoplatform.gui.client.event.shapepreview.FeaturePreviewEvent)1 EPSGLayerData (org.geosdi.geoplatform.gui.client.model.EPSGLayerData)1 GPClientCommand (org.geosdi.geoplatform.gui.command.api.GPClientCommand)1