Search in sources :

Example 6 with GeoObjectType

use of org.commongeoregistry.adapter.metadata.GeoObjectType 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 7 with GeoObjectType

use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.

the class HierarchyService method insertBetweenTypes.

/**
 * Inserts the {@link GeoObjectType} 'middleGeoObjectTypeCode' into the
 * hierarchy as the child of 'parentGeoObjectTypeCode' and the new parent for
 * 'youngestGeoObjectTypeCode'. If an existing parent/child relationship
 * already exists between 'youngestGeoObjectTypeCode' and
 * 'parentgeoObjectTypeCode', it will first be removed.
 * youngestGeoObjectTypeCode can also be an array (comma separated list).
 *
 * @param sessionId
 * @param hierarchyTypeCode
 *          code of the {@link HierarchyType}
 * @param parentGeoObjectTypeCode
 *          parent {@link GeoObjectType}.
 * @param middleGeoObjectTypeCode
 *          middle child {@link GeoObjectType} after this method returns
 * @param youngestGeoObjectTypeCode
 *          youngest child {@link GeoObjectType} after this method returns
 */
@Request(RequestType.SESSION)
public HierarchyType insertBetweenTypes(String sessionId, String hierarchyTypeCode, String parentGeoObjectTypeCode, String middleGeoObjectTypeCode, String youngestGeoObjectTypeCode) {
    ServerHierarchyType type = ServerHierarchyType.get(hierarchyTypeCode);
    ServerGeoObjectType parentType = ServerGeoObjectType.get(parentGeoObjectTypeCode);
    ServerGeoObjectType middleType = ServerGeoObjectType.get(middleGeoObjectTypeCode);
    List<ServerGeoObjectType> youngestTypes = Arrays.asList(youngestGeoObjectTypeCode.split(",")).stream().map(code -> ServerGeoObjectType.get(code.trim())).collect(Collectors.toList());
    ServiceFactory.getGeoObjectTypeRelationshipPermissionService().enforceCanAddChild(type, parentType, middleType);
    type.insertBetween(parentType, middleType, youngestTypes);
    return type.toHierarchyType();
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) Collection(java.util.Collection) RequestType(com.runwaysdk.session.RequestType) GeoRegistryUtil(net.geoprism.registry.GeoRegistryUtil) Set(java.util.Set) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Collectors(java.util.stream.Collectors) Request(com.runwaysdk.session.Request) ServiceFactory(net.geoprism.registry.service.ServiceFactory) PermissionContext(net.geoprism.registry.permission.PermissionContext) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) List(java.util.List) JsonArray(com.google.gson.JsonArray) Organization(net.geoprism.registry.Organization) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) Session(com.runwaysdk.session.Session) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) RolePermissionService(net.geoprism.registry.permission.RolePermissionService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request)

Example 8 with GeoObjectType

use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.

the class HierarchyService method getHierarchiesForType.

@Request(RequestType.SESSION)
public JsonArray getHierarchiesForType(String sessionId, String code, Boolean includeTypes) {
    ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(code);
    List<ServerHierarchyType> hierarchyTypes = ServerHierarchyType.getAll();
    JsonArray hierarchies = new JsonArray();
    HierarchyTypePermissionServiceIF htpService = ServiceFactory.getHierarchyPermissionService();
    GeoObjectRelationshipPermissionServiceIF grpService = ServiceFactory.getGeoObjectRelationshipPermissionService();
    for (ServerHierarchyType sHT : hierarchyTypes) {
        if (htpService.canRead(sHT.getOrganizationCode())) {
            List<GeoObjectType> parents = geoObjectType.getTypeAncestors(sHT, true);
            if (parents.size() > 0 || geoObjectType.isRoot(sHT)) {
                JsonObject object = new JsonObject();
                object.addProperty("code", sHT.getCode());
                object.addProperty("label", sHT.getDisplayLabel().getValue());
                if (includeTypes) {
                    JsonArray pArray = new JsonArray();
                    for (GeoObjectType parent : parents) {
                        ServerGeoObjectType pType = ServerGeoObjectType.get(parent);
                        if (!pType.getCode().equals(geoObjectType.getCode()) && grpService.canViewChild(sHT.getOrganizationCode(), null, pType)) {
                            JsonObject pObject = new JsonObject();
                            pObject.addProperty("code", pType.getCode());
                            pObject.addProperty("label", pType.getLabel().getValue());
                            pArray.add(pObject);
                        }
                    }
                    object.add("parents", pArray);
                }
                hierarchies.add(object);
            }
        }
    }
    if (hierarchies.size() == 0) {
        for (ServerHierarchyType sHT : hierarchyTypes) {
            if (htpService.canWrite(sHT.getOrganizationCode())) {
                if (geoObjectType.isRoot(sHT)) {
                    JsonObject object = new JsonObject();
                    object.addProperty("code", sHT.getCode());
                    object.addProperty("label", sHT.getDisplayLabel().getValue());
                    object.add("parents", new JsonArray());
                    hierarchies.add(object);
                }
            }
        }
    }
    return hierarchies;
}
Also used : JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) GeoObjectRelationshipPermissionServiceIF(net.geoprism.registry.permission.GeoObjectRelationshipPermissionServiceIF) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) Request(com.runwaysdk.session.Request)

Example 9 with GeoObjectType

use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.

the class GeoObjectImportConfiguration method fromJSON.

@Request
public GeoObjectImportConfiguration fromJSON(String json, boolean includeCoordinates) {
    super.fromJSON(json);
    SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    JSONObject config = new JSONObject(json);
    JSONObject type = config.getJSONObject(TYPE);
    JSONArray locations = config.has(LOCATIONS) ? config.getJSONArray(LOCATIONS) : new JSONArray();
    JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
    String code = type.getString(GeoObjectType.JSON_CODE);
    ServerGeoObjectType got = ServerGeoObjectType.get(code);
    this.setType(got);
    this.setIncludeCoordinates(includeCoordinates);
    this.setPostalCode(config.has(POSTAL_CODE) && config.getBoolean(POSTAL_CODE));
    if (config.has(REVEAL_GEOMETRY_COLUMN)) {
        this.setRevealGeometryColumn(config.getString(REVEAL_GEOMETRY_COLUMN));
    }
    try {
        if (config.has(GeoObjectImportConfiguration.START_DATE)) {
            this.setStartDate(format.parse(config.getString(GeoObjectImportConfiguration.START_DATE)));
        }
        if (config.has(GeoObjectImportConfiguration.END_DATE)) {
            this.setEndDate(format.parse(config.getString(GeoObjectImportConfiguration.END_DATE)));
        }
    } catch (ParseException e) {
        throw new ProgrammingErrorException(e);
    }
    if (config.has(HIERARCHY)) {
        String hCode = config.getString(HIERARCHY);
        if (hCode.length() > 0) {
            ServerHierarchyType hierarchyType = ServerHierarchyType.get(hCode);
            List<GeoObjectType> ancestors = got.getTypeAncestors(hierarchyType, true);
            this.setHierarchy(hierarchyType);
            if (ancestors.size() > 0) {
                this.setRoot(null);
            }
        }
    }
    if (config.has(EXCLUSIONS)) {
        JSONArray exclusions = config.getJSONArray(EXCLUSIONS);
        for (int i = 0; i < exclusions.length(); i++) {
            JSONObject exclusion = exclusions.getJSONObject(i);
            String attributeName = exclusion.getString(AttributeType.JSON_CODE);
            String value = exclusion.getString(VALUE);
            this.addExclusion(attributeName, value);
        }
    }
    for (int i = 0; i < attributes.length(); i++) {
        JSONObject attribute = attributes.getJSONObject(i);
        if (attribute.has(TARGET)) {
            String attributeName = attribute.getString(AttributeType.JSON_CODE);
            // In the case of a spreadsheet, this ends up being the column header
            String target = attribute.getString(TARGET);
            if (attribute.has("locale")) {
                String locale = attribute.getString("locale");
                if (this.getFunction(attributeName) == null) {
                    this.setFunction(attributeName, new LocalizedValueFunction());
                }
                LocalizedValueFunction function = (LocalizedValueFunction) this.getFunction(attributeName);
                function.add(locale, new BasicColumnFunction(target));
            } else {
                this.setFunction(attributeName, new BasicColumnFunction(target));
            }
        }
    }
    for (int i = 0; i < locations.length(); i++) {
        JSONObject location = locations.getJSONObject(i);
        if (location.has(TARGET) && location.getString(TARGET).length() > 0 && location.has(MATCH_STRATEGY) && location.getString(MATCH_STRATEGY).length() > 0) {
            String pCode = location.getString(AttributeType.JSON_CODE);
            ServerGeoObjectType pType = ServerGeoObjectType.get(pCode);
            ServerHierarchyType pHierarchy = got.findHierarchy(this.hierarchy, pType);
            String target = location.getString(TARGET);
            ParentMatchStrategy matchStrategy = ParentMatchStrategy.valueOf(location.getString(MATCH_STRATEGY));
            // coming in with use BasicColumnFunctions
            if (location.has("type") && location.getString("type").equals(ConstantShapefileFunction.class.getName())) {
                this.addParent(new Location(pType, pHierarchy, new ConstantShapefileFunction(target), matchStrategy));
            } else {
                this.addParent(new Location(pType, pHierarchy, new BasicColumnFunction(target), matchStrategy));
            }
        }
    }
    // If the hierarchy is inherited, we need to resolve the hierarchy
    // inheritance chain and set them properly on the Location objects
    // To do this, we must start from the bottom and resolve upwards
    ServerHierarchyType ht = this.hierarchy;
    for (int i = this.locations.size() - 1; i >= 0; --i) {
        Location loc = this.locations.get(i);
        ht = got.findHierarchy(ht, loc.getType());
        loc.setHierarchy(ht);
    }
    return this;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) JSONArray(org.json.JSONArray) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONObject(org.json.JSONObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Request(com.runwaysdk.session.Request)

Example 10 with GeoObjectType

use of org.commongeoregistry.adapter.metadata.GeoObjectType in project geoprism-registry by terraframe.

the class ServerGeoObjectType method getTypeAncestors.

/**
 * Returns all ancestors of a GeoObjectType
 *
 * @param hierarchyType
 *          The Hierarchy code
 * @param includeInheritedTypes
 *          TODO
 * @param GeoObjectType
 *          child
 *
 * @return
 */
public List<GeoObjectType> getTypeAncestors(ServerHierarchyType hierarchyType, Boolean includeInheritedTypes) {
    List<GeoObjectType> ancestors = new LinkedList<GeoObjectType>();
    Collection<com.runwaysdk.business.ontology.Term> list = GeoEntityUtil.getOrderedAncestors(Universal.getRoot(), this.getUniversal(), hierarchyType.getUniversalType());
    list.forEach(term -> {
        Universal parent = (Universal) term;
        if (!parent.getKeyName().equals(Universal.ROOT) && !parent.getOid().equals(this.getUniversal().getOid())) {
            ServerGeoObjectType sParent = ServerGeoObjectType.get(parent);
            ancestors.add(sParent.getType());
            if (includeInheritedTypes && sParent.isRoot(hierarchyType)) {
                ServerHierarchyType inheritedHierarchy = sParent.getInheritedHierarchy(hierarchyType);
                if (inheritedHierarchy != null) {
                    ancestors.addAll(0, sParent.getTypeAncestors(inheritedHierarchy, includeInheritedTypes));
                }
            }
        }
    });
    if (ancestors.size() == 0) {
        ServerGeoObjectType superType = this.getSuperType();
        if (superType != null) {
            return superType.getTypeAncestors(hierarchyType, includeInheritedTypes);
        }
    }
    return ancestors;
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) LinkedList(java.util.LinkedList)

Aggregations

GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)33 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)23 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)13 JsonArray (com.google.gson.JsonArray)10 JsonObject (com.google.gson.JsonObject)10 Request (com.runwaysdk.session.Request)10 LinkedList (java.util.LinkedList)7 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)6 Test (org.junit.Test)6 ServerGeoObjectTypeConverter (net.geoprism.registry.conversion.ServerGeoObjectTypeConverter)4 HierarchyNode (org.commongeoregistry.adapter.metadata.HierarchyNode)4 HierarchyType (org.commongeoregistry.adapter.metadata.HierarchyType)4 Endpoint (com.runwaysdk.mvc.Endpoint)3 RestBodyResponse (com.runwaysdk.mvc.RestBodyResponse)3 List (java.util.List)3 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)3 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)2 Universal (com.runwaysdk.system.gis.geo.Universal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2