Search in sources :

Example 1 with MdTermRelationshipQuery

use of com.runwaysdk.system.metadata.MdTermRelationshipQuery in project geoprism-registry by terraframe.

the class PatchHierarchicalRelationshipType method createHierarchicalRelationshipTypes.

public void createHierarchicalRelationshipTypes() {
    MdBusiness univMdBusiness = MdBusiness.getMdBusiness(Universal.CLASS);
    MdTermRelationshipQuery trq = new MdTermRelationshipQuery(new QueryFactory());
    trq.WHERE(trq.getParentMdBusiness().EQ(univMdBusiness).AND(trq.getChildMdBusiness().EQ(univMdBusiness)));
    try (OIterator<? extends MdTermRelationship> it = trq.getIterator()) {
        it.getAll().stream().filter(mdTermRel -> {
            if (!(mdTermRel.definesType().equals(IsARelationship.CLASS) || mdTermRel.getKey().equals(AllowedIn.CLASS) || mdTermRel.getKey().equals(LocatedIn.CLASS))) {
                return (HierarchicalRelationshipType.getByMdTermRelationship(mdTermRel) == null);
            }
            return false;
        }).forEach(mdTermRel -> {
            System.out.println("Creating HierarchicalRelationshipType for the MdTermRelationship [" + mdTermRel.definesType() + "]");
            String code = ServerHierarchyType.buildHierarchyKeyFromMdTermRelUniversal(mdTermRel.getKey());
            String geoEntityKey = ServerHierarchyType.buildMdTermRelGeoEntityKey(code);
            String mdEdgeKey = ServerHierarchyType.buildMdEdgeKey(code);
            MdEdgeDAOIF mdEdge = MdEdgeDAO.getMdEdgeDAO(mdEdgeKey);
            String ownerActerOid = mdTermRel.getOwnerId();
            String organizationCode = Organization.getRootOrganizationCode(ownerActerOid);
            Organization organization = Organization.getByCode(organizationCode);
            HierarchicalRelationshipType hierarchicalRelationship = new HierarchicalRelationshipType();
            hierarchicalRelationship.setCode(code);
            hierarchicalRelationship.setOrganization(organization);
            hierarchicalRelationship.setMdTermRelationshipId(mdTermRel.getOid());
            hierarchicalRelationship.setMdEdgeId(mdEdge.getOid());
            try {
                MdTermRelationship entityRelationship = MdTermRelationship.getByKey(geoEntityKey);
                LocalizedValue displayLabel = AttributeTypeConverter.convert(entityRelationship.getDisplayLabel());
                LocalizedValue description = AttributeTypeConverter.convert(entityRelationship.getDescription());
                LocalizedValueConverter.populate(hierarchicalRelationship.getDisplayLabel(), displayLabel);
                LocalizedValueConverter.populate(hierarchicalRelationship.getDescription(), description);
                entityRelationship.delete();
            } catch (DataNotFoundException | AttributeDoesNotExistException e) {
                logger.debug("The entity geo relationship was not found defaulting to the mdTermRel displayLabel and description");
                LocalizedValue displayLabel = AttributeTypeConverter.convert(mdTermRel.getDisplayLabel());
                LocalizedValue description = AttributeTypeConverter.convert(mdTermRel.getDescription());
                LocalizedValueConverter.populate(hierarchicalRelationship.getDisplayLabel(), displayLabel);
                LocalizedValueConverter.populate(hierarchicalRelationship.getDescription(), description);
            }
            try {
                BusinessDAOIF metadata = BusinessDAO.get("net.geoprism.registry.HierarchyMetadata", mdTermRel.getOid());
                hierarchicalRelationship.setAbstractDescription(metadata.getValue("abstractDescription"));
                hierarchicalRelationship.setAcknowledgement(metadata.getValue("acknowledgement"));
                hierarchicalRelationship.setDisclaimer(metadata.getValue("disclaimer"));
                hierarchicalRelationship.setContact(metadata.getValue("contact"));
                hierarchicalRelationship.setPhoneNumber(metadata.getValue("phoneNumber"));
                hierarchicalRelationship.setEmail(metadata.getValue("email"));
                hierarchicalRelationship.setProgress(metadata.getValue("progress"));
                hierarchicalRelationship.setAccessConstraints(metadata.getValue("accessConstraints"));
                hierarchicalRelationship.setUseConstraints(metadata.getValue("useConstraints"));
            } catch (DataNotFoundException | AttributeDoesNotExistException e) {
            }
            hierarchicalRelationship.apply();
        });
    }
}
Also used : Universal(com.runwaysdk.system.gis.geo.Universal) Transaction(com.runwaysdk.dataaccess.transaction.Transaction) LoggerFactory(org.slf4j.LoggerFactory) AllowedIn(com.runwaysdk.system.gis.geo.AllowedIn) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) Request(com.runwaysdk.session.Request) MdTermRelationshipQuery(com.runwaysdk.system.metadata.MdTermRelationshipQuery) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) HierarchyMetadata(net.geoprism.registry.HierarchyMetadata) Organization(net.geoprism.registry.Organization) LocalizedValueConverter(net.geoprism.registry.conversion.LocalizedValueConverter) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) QueryFactory(com.runwaysdk.query.QueryFactory) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) InheritedHierarchyAnnotation(net.geoprism.registry.InheritedHierarchyAnnotation) InheritedHierarchyAnnotationQuery(net.geoprism.registry.InheritedHierarchyAnnotationQuery) ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) Logger(org.slf4j.Logger) AttributeDoesNotExistException(com.runwaysdk.dataaccess.AttributeDoesNotExistException) MdEdgeDAO(com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO) AttributeTypeConverter(net.geoprism.registry.conversion.AttributeTypeConverter) OIterator(com.runwaysdk.query.OIterator) IsARelationship(com.runwaysdk.system.gis.geo.IsARelationship) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) LocatedIn(com.runwaysdk.system.gis.geo.LocatedIn) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) QueryFactory(com.runwaysdk.query.QueryFactory) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) Organization(net.geoprism.registry.Organization) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) AttributeDoesNotExistException(com.runwaysdk.dataaccess.AttributeDoesNotExistException) MdTermRelationshipQuery(com.runwaysdk.system.metadata.MdTermRelationshipQuery) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship)

Example 2 with MdTermRelationshipQuery

use of com.runwaysdk.system.metadata.MdTermRelationshipQuery in project geoprism-registry by terraframe.

the class TestHierarchyTypeInfo method doesMdTermRelationshipExist.

public Boolean doesMdTermRelationshipExist() {
    String universalKey = ServerHierarchyType.buildMdTermRelUniversalKey(this.getCode());
    MdTermRelationshipQuery uniQuery = new MdTermRelationshipQuery(new QueryFactory());
    uniQuery.WHERE(uniQuery.getKeyName().EQ(universalKey));
    return uniQuery.getCount() > 0;
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) MdTermRelationshipQuery(com.runwaysdk.system.metadata.MdTermRelationshipQuery)

Aggregations

QueryFactory (com.runwaysdk.query.QueryFactory)2 MdTermRelationshipQuery (com.runwaysdk.system.metadata.MdTermRelationshipQuery)2 AttributeDoesNotExistException (com.runwaysdk.dataaccess.AttributeDoesNotExistException)1 BusinessDAO (com.runwaysdk.dataaccess.BusinessDAO)1 BusinessDAOIF (com.runwaysdk.dataaccess.BusinessDAOIF)1 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)1 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 OIterator (com.runwaysdk.query.OIterator)1 Request (com.runwaysdk.session.Request)1 AllowedIn (com.runwaysdk.system.gis.geo.AllowedIn)1 IsARelationship (com.runwaysdk.system.gis.geo.IsARelationship)1 LocatedIn (com.runwaysdk.system.gis.geo.LocatedIn)1 Universal (com.runwaysdk.system.gis.geo.Universal)1 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)1 MdTermRelationship (com.runwaysdk.system.metadata.MdTermRelationship)1 HierarchicalRelationshipType (net.geoprism.registry.HierarchicalRelationshipType)1 HierarchyMetadata (net.geoprism.registry.HierarchyMetadata)1