Search in sources :

Example 1 with MdTermRelationship

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

the class HierarchyMetadata method getHierarchyType.

public static ServerHierarchyType getHierarchyType(String key) {
    HierarchyMetadata hierarchy = HierarchyMetadata.getByKey(key);
    MdTermRelationship mdTermRelationship = hierarchy.getMdTermRelationship();
    ServerHierarchyType hierarchyType = ServerHierarchyType.get(mdTermRelationship);
    return hierarchyType;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship)

Example 2 with MdTermRelationship

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

the class AddWritePermissions method reassignPermissions.

private void reassignPermissions(ServerHierarchyType hierarchyType) {
    RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
    RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
    RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
    InitializationStrategyIF strategy = new InitializationStrategyIF() {

        @Override
        public void preApply(MdBusinessDAO mdBusiness) {
            mdBusiness.setValue(MdBusinessInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
        }

        @Override
        public void postApply(MdBusinessDAO mdBusiness) {
            RoleDAO adminRole = RoleDAO.findRole(DefaultConfiguration.ADMIN).getBusinessDAO();
            adminRole.grantPermission(Operation.READ, mdBusiness.getOid());
            adminRole.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            adminRole.grantPermission(Operation.WRITE, mdBusiness.getOid());
            adminRole.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
            adminRole.grantPermission(Operation.CREATE, mdBusiness.getOid());
            adminRole.grantPermission(Operation.DELETE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.READ, mdBusiness.getOid());
            maintainer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            maintainer.grantPermission(Operation.WRITE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
            maintainer.grantPermission(Operation.CREATE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.DELETE, mdBusiness.getOid());
            consumer.grantPermission(Operation.READ, mdBusiness.getOid());
            consumer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            contributor.grantPermission(Operation.READ, mdBusiness.getOid());
            contributor.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
        }
    };
    String key = GISConstants.GEO_PACKAGE + "." + hierarchyType.getCode() + RegistryConstants.UNIVERSAL_RELATIONSHIP_POST;
    if (hierarchyType.getCode().equals("LocatedIn")) {
        key = GISConstants.GEO_PACKAGE + "." + hierarchyType.getCode();
    }
    MdTermRelationship mdTermRelUniversal = MdTermRelationship.getByKey(key);
    this.grantWritePermissionsOnMdTermRel(mdTermRelUniversal);
    this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelUniversal);
    this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelUniversal);
    this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelUniversal);
    Universal.getStrategy().initialize(mdTermRelUniversal.definesType(), strategy);
    MdTermRelationship mdTermRelGeoEntity = MdTermRelationship.getByKey(GISConstants.GEO_PACKAGE + "." + hierarchyType.getCode());
    this.grantWritePermissionsOnMdTermRel(mdTermRelGeoEntity);
    this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelGeoEntity);
    this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelGeoEntity);
    this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelGeoEntity);
    MdEdgeDAO mdEdge = (MdEdgeDAO) MdEdgeDAO.getMdEdgeDAO(RegistryConstants.UNIVERSAL_GRAPH_PACKAGE + "." + hierarchyType.getCode());
    this.grantWritePermissionsOnMdTermRel(mdEdge);
    this.grantWritePermissionsOnMdTermRel(maintainer, mdEdge);
    this.grantReadPermissionsOnMdTermRel(consumer, mdEdge);
    this.grantReadPermissionsOnMdTermRel(contributor, mdEdge);
    logger.info("Updated permissions for HierarchyType [" + hierarchyType.getCode() + "]. ");
}
Also used : RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) InitializationStrategyIF(com.runwaysdk.business.ontology.InitializationStrategyIF) MdEdgeDAO(com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship)

Example 3 with MdTermRelationship

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

the class ServerHierarchyTypeBuilder method createHierarchyType.

@Transaction
public ServerHierarchyType createHierarchyType(HierarchyType hierarchyType) {
    if (hierarchyType.getOrganizationCode() == null || hierarchyType.getOrganizationCode().equals("")) {
        // TODO : A better exception
        throw new AttributeValueException("Organization code cannot be null.", hierarchyType.getOrganizationCode());
    }
    Organization organization = Organization.getByCode(hierarchyType.getOrganizationCode());
    String addons = new String(RegistryConstants.UNIVERSAL_RELATIONSHIP_POST + "AllPathsTable");
    if (hierarchyType.getCode().length() > (64 - addons.length())) {
        // Initializing the Universal allpaths strategy creates this limitation.
        CodeLengthException ex = new CodeLengthException();
        ex.setLength(64 - addons.length());
        throw ex;
    }
    RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
    RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
    RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
    InitializationStrategyIF strategy = new InitializationStrategyIF() {

        @Override
        public void preApply(MdBusinessDAO mdBusiness) {
            mdBusiness.setValue(MdBusinessInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
        }

        @Override
        public void postApply(MdBusinessDAO mdBusiness) {
            RoleDAO adminRole = RoleDAO.findRole(DefaultConfiguration.ADMIN).getBusinessDAO();
            adminRole.grantPermission(Operation.READ, mdBusiness.getOid());
            adminRole.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            adminRole.grantPermission(Operation.WRITE, mdBusiness.getOid());
            adminRole.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
            adminRole.grantPermission(Operation.CREATE, mdBusiness.getOid());
            adminRole.grantPermission(Operation.DELETE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.READ, mdBusiness.getOid());
            maintainer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            maintainer.grantPermission(Operation.WRITE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
            maintainer.grantPermission(Operation.CREATE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.DELETE, mdBusiness.getOid());
            consumer.grantPermission(Operation.READ, mdBusiness.getOid());
            consumer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            contributor.grantPermission(Operation.READ, mdBusiness.getOid());
            contributor.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
        }
    };
    try {
        MdTermRelationship mdTermRelUniversal = this.newHierarchyToMdTermRelForUniversals(hierarchyType);
        mdTermRelUniversal.apply();
        this.grantWritePermissionsOnMdTermRel(mdTermRelUniversal);
        this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelUniversal);
        this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelUniversal);
        this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelUniversal);
        Universal.getStrategy().initialize(mdTermRelUniversal.definesType(), strategy);
        MdEdge mdEdge = this.createMdEdge(hierarchyType);
        this.grantWritePermissionsOnMdTermRel(mdEdge);
        this.grantWritePermissionsOnMdTermRel(maintainer, mdEdge);
        this.grantReadPermissionsOnMdTermRel(consumer, mdEdge);
        this.grantReadPermissionsOnMdTermRel(contributor, mdEdge);
        HierarchicalRelationshipType hierarchicalRelationship = new HierarchicalRelationshipType();
        hierarchicalRelationship.setCode(hierarchyType.getCode());
        hierarchicalRelationship.setOrganization(organization);
        populate(hierarchicalRelationship.getDisplayLabel(), hierarchyType.getLabel());
        populate(hierarchicalRelationship.getDescription(), hierarchyType.getDescription());
        hierarchicalRelationship.setMdTermRelationship(mdTermRelUniversal);
        hierarchicalRelationship.setMdEdge(mdEdge);
        hierarchicalRelationship.setAbstractDescription(hierarchyType.getAbstractDescription());
        hierarchicalRelationship.setAcknowledgement(hierarchyType.getAcknowledgement());
        hierarchicalRelationship.setDisclaimer(hierarchyType.getDisclaimer());
        hierarchicalRelationship.setContact(hierarchyType.getContact());
        hierarchicalRelationship.setPhoneNumber(hierarchyType.getPhoneNumber());
        hierarchicalRelationship.setEmail(hierarchyType.getEmail());
        hierarchicalRelationship.setProgress(hierarchyType.getProgress());
        hierarchicalRelationship.setAccessConstraints(hierarchyType.getAccessConstraints());
        hierarchicalRelationship.setUseConstraints(hierarchyType.getUseConstraints());
        hierarchicalRelationship.apply();
        return this.get(hierarchicalRelationship);
    } catch (DuplicateDataException ex) {
        DuplicateHierarchyTypeException ex2 = new DuplicateHierarchyTypeException();
        ex2.setDuplicateValue(hierarchyType.getCode());
        throw ex2;
    }
}
Also used : Organization(net.geoprism.registry.Organization) MdEdge(com.runwaysdk.system.metadata.MdEdge) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) DuplicateHierarchyTypeException(net.geoprism.registry.DuplicateHierarchyTypeException) InitializationStrategyIF(com.runwaysdk.business.ontology.InitializationStrategyIF) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) AttributeValueException(com.runwaysdk.dataaccess.attributes.AttributeValueException) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) CodeLengthException(net.geoprism.registry.CodeLengthException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with MdTermRelationship

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

the class HierarchicalRelationshipType method delete.

@Override
@Transaction
public void delete() {
    MdTermRelationship mdTermRelationship = this.getMdTermRelationship();
    MdEdge mdEdge = this.getMdEdge();
    super.delete();
    /*
     * Delete all inherited hierarchies
     */
    List<? extends InheritedHierarchyAnnotation> annotations = InheritedHierarchyAnnotation.getByRelationship(this);
    for (InheritedHierarchyAnnotation annotation : annotations) {
        annotation.delete();
    }
    Universal.getStrategy().shutdown(mdTermRelationship.definesType());
    // AttributeHierarchy.deleteByRelationship(mdTermRelationship);
    mdTermRelationship.delete();
    mdEdge.delete();
}
Also used : MdEdge(com.runwaysdk.system.metadata.MdEdge) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 5 with MdTermRelationship

use of com.runwaysdk.system.metadata.MdTermRelationship 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)

Aggregations

MdTermRelationship (com.runwaysdk.system.metadata.MdTermRelationship)8 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)3 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)3 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)3 InitializationStrategyIF (com.runwaysdk.business.ontology.InitializationStrategyIF)2 RoleDAO (com.runwaysdk.business.rbac.RoleDAO)2 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)2 QueryFactory (com.runwaysdk.query.QueryFactory)2 MdEdge (com.runwaysdk.system.metadata.MdEdge)2 HierarchicalRelationshipType (net.geoprism.registry.HierarchicalRelationshipType)2 Organization (net.geoprism.registry.Organization)2 JsonObject (com.google.gson.JsonObject)1 AttributeDoesNotExistException (com.runwaysdk.dataaccess.AttributeDoesNotExistException)1 BusinessDAO (com.runwaysdk.dataaccess.BusinessDAO)1 BusinessDAOIF (com.runwaysdk.dataaccess.BusinessDAOIF)1 DuplicateDataException (com.runwaysdk.dataaccess.DuplicateDataException)1 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)1 AttributeValueException (com.runwaysdk.dataaccess.attributes.AttributeValueException)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1