Search in sources :

Example 21 with Universal

use of com.runwaysdk.system.gis.geo.Universal in project geoprism-registry by terraframe.

the class CRAttributePatch method patchAllGos.

private void patchAllGos() {
    for (Universal uni : getUniversals()) {
        MdGeoVertexDAO mdVertex = GeoVertexType.getMdGeoVertex(uni.getUniversalId());
        List<? extends MdAttributeDAOIF> attributes = mdVertex.getAllDefinedMdAttributes();
        String[] skipAttrs = new String[] { DefaultAttribute.UID.getName(), "uuid", DefaultAttribute.CODE.getName(), DefaultAttribute.CREATE_DATE.getName(), DefaultAttribute.LAST_UPDATE_DATE.getName(), DefaultAttribute.SEQUENCE.getName(), DefaultAttribute.TYPE.getName(), MdAttributeConcreteInfo.OID, MdAttributeConcreteInfo.SEQUENCE };
        StringBuilder statement = new StringBuilder();
        statement.append("SELECT FROM " + mdVertex.getDBClassName());
        GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
        List<VertexObject> results = query.getResults();
        logger.info("Updating [" + results.size() + "] objects on table [" + mdVertex.getDBClassName() + "].");
        for (VertexObject vo : query.getResults()) {
            for (MdAttributeDAOIF attr : attributes) {
                if (!ArrayUtils.contains(skipAttrs, attr.definesAttribute())) {
                    ValueOverTimeCollection col = vo.getValuesOverTime(attr.definesAttribute());
                    for (ValueOverTime vot : col) {
                        vot.setOid(UUID.randomUUID().toString());
                    }
                }
            }
            vo.apply();
        }
    }
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) VertexObject(com.runwaysdk.business.graph.VertexObject) ValueOverTime(com.runwaysdk.dataaccess.graph.attributes.ValueOverTime) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) ValueOverTimeCollection(com.runwaysdk.dataaccess.graph.attributes.ValueOverTimeCollection) MdGeoVertexDAO(com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 22 with Universal

use of com.runwaysdk.system.gis.geo.Universal in project geoprism-registry by terraframe.

the class PatchGeoObjectTypeMetadata method doIt.

@Transaction
private void doIt() {
    QueryFactory qf = new QueryFactory();
    UniversalQuery uq = new UniversalQuery(qf);
    OIterator<? extends Universal> it = uq.getIterator();
    try {
        while (it.hasNext()) {
            Universal uni = it.next();
            if (uni.getKey().equals(Universal.ROOT_KEY)) {
                continue;
            }
            GeoObjectTypeMetadataQuery query = new GeoObjectTypeMetadataQuery(new QueryFactory());
            query.WHERE(query.getKeyName().EQ(uni.getKey()));
            OIterator<? extends GeoObjectTypeMetadata> it2 = query.getIterator();
            try {
                if (!it2.hasNext()) {
                    GeoObjectTypeMetadata metadata = new GeoObjectTypeMetadata();
                    metadata.setUniversal(uni);
                    metadata.setIsPrivate(false);
                    metadata.apply();
                }
            } finally {
                it2.close();
            }
        }
    } finally {
        it.close();
    }
}
Also used : GeoObjectTypeMetadata(net.geoprism.registry.model.GeoObjectTypeMetadata) QueryFactory(com.runwaysdk.query.QueryFactory) Universal(com.runwaysdk.system.gis.geo.Universal) UniversalQuery(com.runwaysdk.system.gis.geo.UniversalQuery) GeoObjectTypeMetadataQuery(net.geoprism.registry.model.GeoObjectTypeMetadataQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 23 with Universal

use of com.runwaysdk.system.gis.geo.Universal in project geoprism-registry by terraframe.

the class ServerGeoObjectTypeConverter method create.

@Transaction
public ServerGeoObjectType create(GeoObjectType geoObjectType) {
    if (!MasterList.isValidName(geoObjectType.getCode())) {
        throw new InvalidMasterListCodeException("The geo object type code has an invalid character");
    }
    if (geoObjectType.getCode().length() > 64) {
        // Setting the typename on the MdBusiness creates this limitation.
        CodeLengthException ex = new CodeLengthException();
        ex.setLength(64);
        throw ex;
    }
    ServiceFactory.getGeoObjectTypePermissionService().enforceCanCreate(geoObjectType.getOrganizationCode(), geoObjectType.getIsPrivate());
    String superTypeCode = geoObjectType.getSuperTypeCode();
    Boolean isAbstract = geoObjectType.getIsAbstract();
    ServerGeoObjectType superType = null;
    if (superTypeCode != null && superTypeCode.length() > 0) {
        superType = ServerGeoObjectType.get(superTypeCode);
        geoObjectType.setGeometryType(superType.getGeometryType());
    }
    if (isAbstract && superType != null) {
        throw new ChainInheritanceException();
    }
    if (superType != null && !superType.getIsAbstract()) {
        throw new GeoObjectTypeAssignmentException();
    }
    Universal universal = new Universal();
    universal.setUniversalId(geoObjectType.getCode());
    universal.setIsLeafType(false);
    universal.setIsGeometryEditable(geoObjectType.isGeometryEditable());
    // Set the owner of the universal to the id of the corresponding role of the
    // responsible organization.
    String organizationCode = geoObjectType.getOrganizationCode();
    setOwner(universal, organizationCode);
    populate(universal.getDisplayLabel(), geoObjectType.getLabel());
    populate(universal.getDescription(), geoObjectType.getDescription());
    com.runwaysdk.system.gis.geo.GeometryType geometryType = GeometryTypeFactory.get(geoObjectType.getGeometryType());
    // Clear the default value
    universal.clearGeometryType();
    universal.addGeometryType(geometryType);
    MdBusiness mdBusiness = new MdBusiness();
    mdBusiness.setPackageName(RegistryConstants.UNIVERSAL_MDBUSINESS_PACKAGE);
    // The CODE name becomes the class name
    mdBusiness.setTypeName(universal.getUniversalId());
    mdBusiness.setGenerateSource(false);
    mdBusiness.setIsAbstract(isAbstract);
    mdBusiness.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, universal.getDisplayLabel().getValue());
    mdBusiness.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, universal.getDescription().getValue());
    if (superType != null) {
        mdBusiness.setSuperMdBusiness(superType.getMdBusiness());
    } else {
        mdBusiness.setPublish(false);
    }
    try {
        // The DuplicateDataException on code was found to be thrown here.
        // I've created a larger try/catch here just in case.
        mdBusiness.apply();
        // Add the default attributes.
        if (superType == null) {
            this.createDefaultAttributes(universal, mdBusiness);
        }
        universal.setMdBusiness(mdBusiness);
        universal.apply();
        GeoObjectTypeMetadata metadata = new GeoObjectTypeMetadata();
        metadata.setIsPrivate(geoObjectType.getIsPrivate());
        metadata.setUniversal(universal);
        metadata.apply();
    } catch (DuplicateDataException ex) {
        DuplicateGeoObjectTypeException ex2 = new DuplicateGeoObjectTypeException();
        ex2.setDuplicateValue(geoObjectType.getCode());
        throw ex2;
    }
    // Create the MdGeoVertexClass
    MdGeoVertexDAO mdVertex = GeoVertexType.create(universal.getUniversalId(), universal.getOwnerOid(), isAbstract, superType);
    if (superType == null) {
        this.createDefaultAttributes(universal, mdVertex);
        assignSRAPermissions(mdVertex, mdBusiness);
        assignAll_RA_Permissions(mdVertex, mdBusiness, organizationCode);
        create_RM_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
        assign_RM_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
        create_RC_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
        assign_RC_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
        create_AC_GeoObjectTypeRole(mdVertex, organizationCode, geoObjectType.getCode());
        assign_AC_GeoObjectTypeRole(mdVertex, mdBusiness, organizationCode, geoObjectType.getCode());
    }
    if (!isAbstract) {
        // DefaultAttribute.CODE
        MdAttributeCharacter businessCodeMdAttr = new MdAttributeCharacter();
        businessCodeMdAttr.setAttributeName(DefaultAttribute.CODE.getName());
        businessCodeMdAttr.getDisplayLabel().setValue(DefaultAttribute.CODE.getDefaultLocalizedName());
        businessCodeMdAttr.getDescription().setValue(DefaultAttribute.CODE.getDefaultDescription());
        businessCodeMdAttr.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
        businessCodeMdAttr.setDefiningMdClass(mdBusiness);
        businessCodeMdAttr.setRequired(true);
        businessCodeMdAttr.addIndexType(MdAttributeIndices.UNIQUE_INDEX);
        businessCodeMdAttr.apply();
        // DefaultAttribute.CODE
        MdAttributeCharacterDAO vertexCodeMdAttr = MdAttributeCharacterDAO.newInstance();
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.CODE.getName());
        vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultLocalizedName());
        vertexCodeMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.CODE.getDefaultDescription());
        vertexCodeMdAttr.setValue(MdAttributeCharacterInfo.SIZE, MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, mdVertex.getOid());
        vertexCodeMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
        vertexCodeMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.UNIQUE_INDEX.getOid());
        vertexCodeMdAttr.apply();
    }
    // Build the parent class term root if it does not exist.
    TermConverter.buildIfNotExistdMdBusinessClassifier(mdBusiness);
    ServerGeoObjectType serverGeoObjectType = this.build(universal);
    return serverGeoObjectType;
}
Also used : GeoObjectTypeMetadata(net.geoprism.registry.model.GeoObjectTypeMetadata) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Universal(com.runwaysdk.system.gis.geo.Universal) ChainInheritanceException(net.geoprism.registry.ChainInheritanceException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) InvalidMasterListCodeException(net.geoprism.registry.InvalidMasterListCodeException) MdAttributeCharacterDAO(com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) DuplicateGeoObjectTypeException(net.geoprism.registry.DuplicateGeoObjectTypeException) MdGeoVertexDAO(com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO) GeoObjectTypeAssignmentException(net.geoprism.registry.GeoObjectTypeAssignmentException) CodeLengthException(net.geoprism.registry.CodeLengthException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 24 with Universal

use of com.runwaysdk.system.gis.geo.Universal in project geoprism-registry by terraframe.

the class AbstractServerGeoObject method getHierarchiesForGeoObject.

public JsonArray getHierarchiesForGeoObject(Date date) {
    ServerGeoObjectType geoObjectType = this.getType();
    List<ServerHierarchyType> hierarchyTypes = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
    JsonArray hierarchies = new JsonArray();
    Universal root = Universal.getRoot();
    for (ServerHierarchyType sType : hierarchyTypes) {
        if (ServiceFactory.getHierarchyPermissionService().canWrite(sType.getOrganization().getCode())) {
            // Note: Ordered ancestors always includes self
            Collection<?> uniParents = GeoEntityUtil.getOrderedAncestors(root, geoObjectType.getUniversal(), sType.getUniversalType());
            ParentTreeNode ptnAncestors = this.getParentGeoObjects(null, true, date).toNode(true);
            if (uniParents.size() > 1) {
                JsonObject object = new JsonObject();
                object.addProperty("code", sType.getCode());
                object.addProperty("label", sType.getDisplayLabel().getValue());
                JsonArray pArray = new JsonArray();
                for (Object parent : uniParents) {
                    ServerGeoObjectType pType = ServerGeoObjectType.get((Universal) parent);
                    if (!pType.getCode().equals(geoObjectType.getCode())) {
                        JsonObject pObject = new JsonObject();
                        pObject.addProperty("code", pType.getCode());
                        pObject.addProperty("label", pType.getLabel().getValue());
                        List<ParentTreeNode> ptns = ptnAncestors.findParentOfType(pType.getCode());
                        for (ParentTreeNode ptn : ptns) {
                            if (ptn.getHierachyType().getCode().equals(sType.getCode())) {
                                pObject.add("ptn", ptn.toJSON());
                                // TODO Sibling ancestors
                                break;
                            }
                        }
                        pArray.add(pObject);
                    }
                }
                object.add("parents", pArray);
                hierarchies.add(object);
            }
        }
    }
    if (hierarchies.size() == 0) {
        for (ServerHierarchyType hierarchyType : hierarchyTypes) {
            if (ServiceFactory.getHierarchyPermissionService().canWrite(hierarchyType.getOrganization().getCode())) {
                JsonObject object = new JsonObject();
                object.addProperty("code", hierarchyType.getCode());
                object.addProperty("label", hierarchyType.getDisplayLabel().getValue());
                object.add("parents", new JsonArray());
                hierarchies.add(object);
            }
        }
    }
    return hierarchies;
}
Also used : JsonArray(com.google.gson.JsonArray) Universal(com.runwaysdk.system.gis.geo.Universal) ParentTreeNode(org.commongeoregistry.adapter.dataaccess.ParentTreeNode) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject)

Example 25 with Universal

use of com.runwaysdk.system.gis.geo.Universal in project geoprism-registry by terraframe.

the class ServerGeoObjectType method update.

public void update(GeoObjectType geoObjectTypeNew) {
    GeoObjectType geoObjectTypeModified = this.type.copy(geoObjectTypeNew);
    Universal universal = updateGeoObjectType(geoObjectTypeModified);
    ServerGeoObjectType geoObjectTypeModifiedApplied = new ServerGeoObjectTypeConverter().build(universal);
    // If this did not error out then add to the cache
    ServiceFactory.getMetadataCache().refreshGeoObjectType(geoObjectTypeModifiedApplied);
    // isPrivate). We should refresh them as well.
    if (geoObjectTypeModifiedApplied.getIsAbstract()) {
        List<ServerGeoObjectType> subtypes = geoObjectTypeModifiedApplied.getSubtypes();
        for (ServerGeoObjectType subtype : subtypes) {
            ServerGeoObjectType refreshedSubtype = new ServerGeoObjectTypeConverter().build(subtype.getUniversal());
            ServiceFactory.getMetadataCache().refreshGeoObjectType(refreshedSubtype);
        }
    }
    this.type = geoObjectTypeModifiedApplied.getType();
    this.universal = geoObjectTypeModifiedApplied.getUniversal();
    this.mdBusiness = geoObjectTypeModifiedApplied.getMdBusiness();
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) ServerGeoObjectTypeConverter(net.geoprism.registry.conversion.ServerGeoObjectTypeConverter) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType)

Aggregations

Universal (com.runwaysdk.system.gis.geo.Universal)26 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)8 QueryFactory (com.runwaysdk.query.QueryFactory)7 LinkedList (java.util.LinkedList)7 ServerGeoObjectTypeConverter (net.geoprism.registry.conversion.ServerGeoObjectTypeConverter)6 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)5 UniversalQuery (com.runwaysdk.system.gis.geo.UniversalQuery)5 JsonObject (com.google.gson.JsonObject)3 MdGraphClassDAOIF (com.runwaysdk.dataaccess.MdGraphClassDAOIF)3 MdGeoVertexDAO (com.runwaysdk.gis.dataaccess.metadata.graph.MdGeoVertexDAO)3 JsonArray (com.google.gson.JsonArray)2 Term (com.runwaysdk.business.ontology.Term)2 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)2 ValueOverTime (com.runwaysdk.dataaccess.graph.attributes.ValueOverTime)2 MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)2 List (java.util.List)2 Organization (net.geoprism.registry.Organization)2 GeoObjectTypeMetadata (net.geoprism.registry.model.GeoObjectTypeMetadata)2 Term (org.commongeoregistry.adapter.Term)2 GeoObjectType (org.commongeoregistry.adapter.metadata.GeoObjectType)2