Search in sources :

Example 16 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class HierarchyService method removeInheritedHierarchy.

/**
 * Modifies a hierarchy to remove inheritance from another hierarchy for the
 * given root
 *
 * @param sessionId
 * @param hierarchyTypeCode
 *          code of the {@link HierarchyType} being modified.
 * @param geoObjectTypeCode
 *          code of the root {@link GeoObjectType}.
 */
@Request(RequestType.SESSION)
public HierarchyType removeInheritedHierarchy(String sessionId, String hierarchyTypeCode, String geoObjectTypeCode) {
    ServerHierarchyType forHierarchy = ServerHierarchyType.get(hierarchyTypeCode);
    ServerGeoObjectType childType = ServerGeoObjectType.get(geoObjectTypeCode);
    ServiceFactory.getGeoObjectTypeRelationshipPermissionService().enforceCanAddChild(forHierarchy, null, childType);
    ServerGeoObjectType type = ServerGeoObjectType.get(geoObjectTypeCode);
    type.removeInheritedHierarchy(forHierarchy);
    forHierarchy.refresh();
    return forHierarchy.toHierarchyType();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Request(com.runwaysdk.session.Request)

Example 17 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class HierarchyService method getHierarchyGroupedTypes.

@Request(RequestType.SESSION)
public JsonArray getHierarchyGroupedTypes(String sessionId) {
    final HierarchyTypePermissionServiceIF hierarchyPermissions = ServiceFactory.getHierarchyPermissionService();
    final GeoObjectTypePermissionServiceIF typePermissions = ServiceFactory.getGeoObjectTypePermissionService();
    final RolePermissionService rps = ServiceFactory.getRolePermissionService();
    final boolean isSRA = rps.isSRA();
    JsonArray allHiers = new JsonArray();
    List<ServerHierarchyType> shts = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    for (ServerHierarchyType sht : shts) {
        final String htOrgCode = sht.getOrganizationCode();
        if (hierarchyPermissions.canRead(htOrgCode) && (isSRA || rps.isRA(htOrgCode) || rps.isRM(htOrgCode))) {
            JsonObject hierView = new JsonObject();
            hierView.addProperty("code", sht.getCode());
            hierView.addProperty("label", sht.getDisplayLabel().getValue());
            hierView.addProperty("orgCode", sht.getOrganizationCode());
            JsonArray allHierTypes = new JsonArray();
            List<ServerGeoObjectType> types = sht.getAllTypes();
            for (ServerGeoObjectType type : types) {
                final String gotOrgCode = type.getOrganizationCode();
                if (typePermissions.canRead(gotOrgCode, type, type.getIsPrivate()) && (isSRA || rps.isRA(gotOrgCode) || rps.isRM(gotOrgCode, type))) {
                    if (type.getIsAbstract()) {
                        JsonObject superView = new JsonObject();
                        superView.addProperty("code", type.getCode());
                        superView.addProperty("label", type.getLabel().getValue());
                        superView.addProperty("orgCode", type.getOrganizationCode());
                        superView.addProperty("isAbstract", true);
                        List<ServerGeoObjectType> subtypes = type.getSubtypes();
                        for (ServerGeoObjectType subtype : subtypes) {
                            JsonObject typeView = new JsonObject();
                            typeView.addProperty("code", subtype.getCode());
                            typeView.addProperty("label", subtype.getLabel().getValue());
                            typeView.addProperty("orgCode", subtype.getOrganization().getCode());
                            typeView.add("super", superView);
                            allHierTypes.add(typeView);
                        }
                    } else {
                        JsonObject typeView = new JsonObject();
                        typeView.addProperty("code", type.getCode());
                        typeView.addProperty("label", type.getLabel().getValue());
                        typeView.addProperty("orgCode", type.getOrganizationCode());
                        allHierTypes.add(typeView);
                    }
                }
            }
            hierView.add("types", allHierTypes);
            allHiers.add(hierView);
        }
    }
    return allHiers;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) JsonArray(com.google.gson.JsonArray) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyTypePermissionServiceIF(net.geoprism.registry.permission.HierarchyTypePermissionServiceIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF) Request(com.runwaysdk.session.Request)

Example 18 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class HierarchyService method updateHierarchyType.

/**
 * Updates the given {@link HierarchyType} represented as JSON.
 *
 * @param sessionId
 * @param gtJSON
 *          JSON of the {@link HierarchyType} to be updated.
 */
@Request(RequestType.SESSION)
public HierarchyType updateHierarchyType(String sessionId, String htJSON) {
    HierarchyType hierarchyType = HierarchyType.fromJSON(htJSON, ServiceFactory.getAdapter());
    ServerHierarchyType type = ServerHierarchyType.get(hierarchyType);
    ServiceFactory.getHierarchyPermissionService().enforceCanWrite(type.getOrganization().getCode());
    type.update(hierarchyType);
    return type.toHierarchyType();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HierarchyType(org.commongeoregistry.adapter.metadata.HierarchyType) Request(com.runwaysdk.session.Request)

Example 19 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType 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 20 with ServerHierarchyType

use of net.geoprism.registry.model.ServerHierarchyType in project geoprism-registry by terraframe.

the class HierarchyService method deleteHierarchyType.

/**
 * Deletes the {@link HierarchyType} with the given code.
 *
 * @param sessionId
 * @param code
 *          code of the {@link HierarchyType} to delete.
 */
@Request(RequestType.SESSION)
public void deleteHierarchyType(String sessionId, String code) {
    ServerHierarchyType type = ServerHierarchyType.get(code);
    ServiceFactory.getHierarchyPermissionService().enforceCanDelete(type.getOrganization().getCode());
    type.delete();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Request(com.runwaysdk.session.Request)

Aggregations

ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)86 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)55 Request (com.runwaysdk.session.Request)38 JsonObject (com.google.gson.JsonObject)20 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)18 Test (org.junit.Test)17 JsonArray (com.google.gson.JsonArray)16 LinkedList (java.util.LinkedList)14 List (java.util.List)14 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)12 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 Locale (java.util.Locale)10 Point (com.vividsolutions.jts.geom.Point)9 ServerParentTreeNode (net.geoprism.registry.model.ServerParentTreeNode)9 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)8 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)8 InheritedHierarchyAnnotation (net.geoprism.registry.InheritedHierarchyAnnotation)8 Organization (net.geoprism.registry.Organization)8