All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.pdok.workspacebuilder.model.layer.DbLayer Maven / Gradle / Ivy

The newest version!
package nl.pdok.workspacebuilder.model.layer;

import nl.pdok.catalogus.Catalogus;
import nl.pdok.workspacebuilder.GeoserverRestProxy;
import nl.pdok.workspacebuilder.PdokBuilder;
import nl.pdok.workspacebuilder.model.Style;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import org.apache.commons.lang.StringUtils;

/**
 * Created with IntelliJ IDEA.
 * User: nijhur
 * Date: 4-3-14
 * Time: 14:56
 * To change this template use File | Settings | File Templates.
 */
public class DbLayer extends SingleLayer {

    public DbLayer(Catalogus catalogus){
        super(Type.DB, catalogus);
    }

    public DbLayer(String name, Style style, Catalogus catalogus){
        super(Type.DB, catalogus);
        setName(name);
        setDefaultStyle(style);
    }

	@Override
	protected GSFeatureTypeEncoder createResourceEncoder() {
		GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder();
		featureTypeEncoder.setName(getName());
		featureTypeEncoder.setNativeName( StringUtils.isEmpty(getNativeName()) ? getName() : getNativeName());
		featureTypeEncoder.setTitle(getTitle());
		featureTypeEncoder.setAbstract(getAbstractText());
		featureTypeEncoder.addMetadataLinkInfo(new GSMetadataLinkInfoEncoder(PdokBuilder.METADATACODETYPE, PdokBuilder.METADATATYPE, PdokBuilder.METADATABASEURL + getMetadataId()));
		featureTypeEncoder.setSRS("EPSG:28992");
		featureTypeEncoder.setProjectionPolicy(GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED);
		featureTypeEncoder.setNativeCRS("EPSG:28992");
		return featureTypeEncoder;
	}



	@Override
    protected boolean publish(String workspaceName, GSResourceEncoder resourceEncoder, GSLayerEncoder layerEncoder, GeoserverRestProxy geoserverRestProxy) {
    	if (geoserverRestProxy.getReader().existsLayer(workspaceName, getName())) {
    		return geoserverRestProxy.getPublisher().configureLayer(workspaceName, getName(), layerEncoder);
    	} else	{
    		return geoserverRestProxy.getPublisher().publishDBLayer(workspaceName, getDatastoreName(), (GSFeatureTypeEncoder) resourceEncoder, layerEncoder );
    	}
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy