Search in sources :

Example 51 with ServerHierarchyType

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

the class Organization method delete.

/**
 * Removes the {@link RoleDAO}s for this {@link Organization} and Registry
 * Administrator for this {@link Organization}.
 */
public void delete() {
    // Can't delete if there's existing data
    List<ServerHierarchyType> hierarchyTypes = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    for (ServerHierarchyType ht : hierarchyTypes) {
        if (ht.getOrganizationCode().equals(this.getCode())) {
            throw new ObjectHasDataException();
        }
    }
    try {
        Roles raOrgRole = this.getRegistryAdminiRole();
        raOrgRole.delete();
    }// Heads up: clean up
     catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
    }
    try {
        Roles orgRole = this.getRole();
        orgRole.delete();
    }// Heads up: clean up
     catch (com.runwaysdk.dataaccess.cache.DataNotFoundException e) {
    }
    super.delete();
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Roles(com.runwaysdk.system.Roles)

Example 52 with ServerHierarchyType

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

the class AddChildAction method execute.

@Override
public void execute() {
    ServerGeoObjectIF parent = new ServerGeoObjectService(new AllowAllGeoObjectPermissionService()).getGeoObject(this.getParentId(), this.getParentTypeCode());
    ServerGeoObjectIF child = new ServerGeoObjectService().getGeoObject(this.getChildId(), this.getChildTypeCode());
    ServerHierarchyType ht = ServerHierarchyType.get(this.getHierarchyTypeCode());
    ServiceFactory.getGeoObjectRelationshipPermissionService().enforceCanAddChild(ht.getOrganization().getCode(), parent.getType(), child.getType());
    parent.addChild(child, ht);
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) AllowAllGeoObjectPermissionService(net.geoprism.registry.permission.AllowAllGeoObjectPermissionService)

Example 53 with ServerHierarchyType

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

the class Transition method createTask.

public void createTask(VertexServerGeoObject source, VertexServerGeoObject target, Date eventDate) {
    LocalizedValue dateValue = LocalizedValueConverter.convert(eventDate);
    TransitionType transitionType = this.toTransitionType();
    ServerGeoObjectType sourceType = source.getType();
    ServerGeoObjectType targetType = target.getType();
    List<ServerGeoObjectType> types = Arrays.asList(new ServerGeoObjectType[] { sourceType, targetType }).stream().distinct().collect(Collectors.toList());
    for (ServerGeoObjectType type : types) {
        List<ServerHierarchyType> hierarchies = type.getHierarchies();
        for (ServerHierarchyType hierarchy : hierarchies) {
            List<ServerGeoObjectType> children = type.getChildren(hierarchy);
            for (ServerGeoObjectType child : children) {
                List<Roles> roles = Arrays.asList(new String[] { child.getMaintainerRoleName(), child.getAdminRoleName() }).stream().distinct().map(name -> Roles.findRoleByName(name)).collect(Collectors.toList());
                HashMap<String, LocalizedValue> values = new HashMap<String, LocalizedValue>();
                values.put("1", source.getDisplayLabel());
                values.put("2", sourceType.getLabel());
                values.put("3", target.getDisplayLabel());
                values.put("4", targetType.getLabel());
                values.put("5", child.getLabel());
                values.put("6", hierarchy.getLabel());
                values.put("7", dateValue);
                TaskType taskType = Task.TaskType.SPLIT_EVENT_TASK;
                if (transitionType.isMerge()) {
                    taskType = Task.TaskType.MERGE_EVENT_TASK;
                } else if (transitionType.isReassign()) {
                    taskType = Task.TaskType.REASSIGN_EVENT_TASK;
                }
                Task.createNewTask(roles, taskType, values, this.getOid());
            }
        }
    }
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Task(net.geoprism.registry.task.Task) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) VertexGeoObjectStrategy(net.geoprism.registry.conversion.VertexGeoObjectStrategy) Date(java.util.Date) GraphQuery(com.runwaysdk.business.graph.GraphQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) VertexObject(com.runwaysdk.business.graph.VertexObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) HashMap(java.util.HashMap) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Roles(com.runwaysdk.system.Roles) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Collectors(java.util.stream.Collectors) TaskType(net.geoprism.registry.task.Task.TaskType) MdVertexDAO(com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO) MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) List(java.util.List) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) HashMap(java.util.HashMap) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Roles(com.runwaysdk.system.Roles) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) TaskType(net.geoprism.registry.task.Task.TaskType)

Example 54 with ServerHierarchyType

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

the class SynchronizationConfigPatch method patchJobs.

@Transaction
private void patchJobs() {
    SynchronizationConfigQuery query = new SynchronizationConfigQuery(new QueryFactory());
    logger.info("Attempting to patch " + query.getCount() + " synchronization configs.");
    long count = 0;
    try (OIterator<? extends SynchronizationConfig> iterator = query.getIterator()) {
        while (iterator.hasNext()) {
            SynchronizationConfig config = iterator.next();
            ExternalSystem system = config.getExternalSystem();
            if (system instanceof DHIS2ExternalSystem) {
                JsonObject json = config.getConfigurationJson();
                ServerHierarchyType hierarchy = null;
                MdTermRelationship universalRelationship = config.getHierarchy();
                if (universalRelationship != null) {
                    hierarchy = ServerHierarchyType.get(universalRelationship);
                } else if (json.has("hierarchy")) {
                    hierarchy = ServerHierarchyType.get(json.get("hierarchy").getAsString());
                } else if (json.has("hierarchyCode")) {
                    hierarchy = ServerHierarchyType.get(json.get("hierarchyCode").getAsString());
                }
                if (hierarchy != null) {
                    json.remove("hierarchy");
                    json.addProperty(DHIS2SyncConfig.HIERARCHY, hierarchy.getCode());
                    config.appLock();
                    config.setConfiguration(json.toString());
                    config.apply();
                    count++;
                } else {
                    logger.error("Skipping " + config.getKey() + " because we couldn't resolve a hierarchy.");
                }
            }
        }
    }
    logger.info("Successfully patched " + count + " synchronization configs.");
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) QueryFactory(com.runwaysdk.query.QueryFactory) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) SynchronizationConfigQuery(net.geoprism.registry.SynchronizationConfigQuery) JsonObject(com.google.gson.JsonObject) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 55 with ServerHierarchyType

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

the class BusinessObjectImportConfiguration method fromJSON.

@Request
public BusinessObjectImportConfiguration fromJSON(String json, boolean includeCoordinates) {
    super.fromJSON(json);
    SimpleDateFormat format = new SimpleDateFormat(BusinessObjectImportConfiguration.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);
    BusinessType businessType = BusinessType.getByCode(code);
    this.setType(businessType);
    try {
        if (config.has(BusinessObjectImportConfiguration.DATE)) {
            this.setDate(format.parse(config.getString(BusinessObjectImportConfiguration.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);
            this.setHierarchy(hierarchyType);
        }
    }
    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);
            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.addLocation(new Location(pType, this.hierarchy, new ConstantShapefileFunction(target), matchStrategy));
            } else {
                this.addLocation(new Location(pType, this.hierarchy, new BasicColumnFunction(target), matchStrategy));
            }
        }
    }
    return this;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ConstantShapefileFunction(net.geoprism.registry.io.ConstantShapefileFunction) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JSONArray(org.json.JSONArray) BusinessType(net.geoprism.registry.BusinessType) LocalizedValueFunction(net.geoprism.registry.io.LocalizedValueFunction) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONObject(org.json.JSONObject) ParseException(java.text.ParseException) ParentMatchStrategy(net.geoprism.registry.io.ParentMatchStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Location(net.geoprism.registry.io.Location) 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