Search in sources :

Example 1 with ImportAttributeSerializer

use of net.geoprism.registry.io.ImportAttributeSerializer in project geoprism-registry by terraframe.

the class GeoObjectExcelExporter method createWorkbook.

public Workbook createWorkbook() throws IOException {
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(this.type.getLabel().getValue()));
    CreationHelper createHelper = workbook.getCreationHelper();
    Font font = workbook.createFont();
    font.setBold(true);
    CellStyle boldStyle = workbook.createCellStyle();
    boldStyle.setFont(font);
    CellStyle dateStyle = workbook.createCellStyle();
    dateStyle.setDataFormat(createHelper.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(14)));
    Row header = sheet.createRow(0);
    boolean includeCoordinates = this.type.getGeometryType().equals(GeometryType.POINT) || this.type.getGeometryType().equals(GeometryType.MIXED);
    Collection<AttributeType> attributes = new ImportAttributeSerializer(Session.getCurrentLocale(), includeCoordinates, true, locales).attributes(this.type.getType());
    // Get the ancestors of the type
    List<GeoObjectType> dtoAncestors = this.type.getTypeAncestors(this.hierarchy, true);
    List<ServerGeoObjectType> ancestors = new LinkedList<ServerGeoObjectType>();
    for (GeoObjectType ancestor : dtoAncestors) {
        ancestors.add(ServerGeoObjectType.get(ancestor));
    }
    this.writeHeader(boldStyle, header, attributes, ancestors);
    for (int i = 0; i < this.objects.size(); i++) {
        ServerGeoObjectIF object = this.objects.get(i);
        Row row = sheet.createRow(i + 1);
        this.writeRow(row, object, attributes, ancestors, dateStyle);
    }
    return workbook;
}
Also used : ImportAttributeSerializer(net.geoprism.registry.io.ImportAttributeSerializer) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Font(org.apache.poi.ss.usermodel.Font) LinkedList(java.util.LinkedList) Point(com.vividsolutions.jts.geom.Point) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 2 with ImportAttributeSerializer

use of net.geoprism.registry.io.ImportAttributeSerializer in project geoprism-registry by terraframe.

the class ExcelService method getType.

private JSONObject getType(ServerGeoObjectType geoObjectType) {
    final boolean includeCoordinates = geoObjectType.getGeometryType().equals(GeometryType.POINT) || geoObjectType.getGeometryType().equals(GeometryType.MULTIPOINT) || geoObjectType.getGeometryType().equals(GeometryType.MIXED);
    final ImportAttributeSerializer serializer = new ImportAttributeSerializer(Session.getCurrentLocale(), includeCoordinates, false, LocalizationFacade.getInstalledLocales());
    JSONObject type = new JSONObject(geoObjectType.toJSON(serializer).toString());
    JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
    for (int i = 0; i < attributes.length(); i++) {
        JSONObject attribute = attributes.getJSONObject(i);
        String attributeType = attribute.getString(AttributeType.JSON_TYPE);
        attribute.put(GeoObjectImportConfiguration.BASE_TYPE, GeoObjectImportConfiguration.getBaseType(attributeType));
    }
    return type;
}
Also used : ImportAttributeSerializer(net.geoprism.registry.io.ImportAttributeSerializer) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 3 with ImportAttributeSerializer

use of net.geoprism.registry.io.ImportAttributeSerializer in project geoprism-registry by terraframe.

the class ShapefileService method getType.

private JSONObject getType(ServerGeoObjectType geoObjectType) {
    JSONObject type = new JSONObject(geoObjectType.toJSON(new ImportAttributeSerializer(Session.getCurrentLocale(), false, false, LocalizationFacade.getInstalledLocales())).toString());
    JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
    for (int i = 0; i < attributes.length(); i++) {
        JSONObject attribute = attributes.getJSONObject(i);
        String attributeType = attribute.getString(AttributeType.JSON_TYPE);
        attribute.put(GeoObjectImportConfiguration.BASE_TYPE, GeoObjectImportConfiguration.getBaseType(attributeType));
    }
    return type;
}
Also used : ImportAttributeSerializer(net.geoprism.registry.io.ImportAttributeSerializer) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Aggregations

ImportAttributeSerializer (net.geoprism.registry.io.ImportAttributeSerializer)3 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Point (com.vividsolutions.jts.geom.Point)1 LinkedList (java.util.LinkedList)1 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)1 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)1 Font (org.apache.poi.ss.usermodel.Font)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)1 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)1