Search in sources :

Example 1 with BusinessDAOIF

use of com.runwaysdk.dataaccess.BusinessDAOIF in project geoprism-registry by terraframe.

the class HierarchyExporter method exportHierarchyDefinition.

/**
 * Exports the metadata for the hierarchies. If a
 * file of the specified filename already exists then the file is overwritten.
 *
 * @param fileName
 *            The name of the xml file to create.
 * @param schemaLocation
 *            The location of the schema
 * @param _exportOnlyModifiedAttributes
 *             True if only modified attributes should be exported, false otherwise.
 */
@Request
public static void exportHierarchyDefinition(String fileName, String schemaLocation, boolean _exportOnlyModifiedAttributes) {
    ExportMetadata exportMetadata = new ExportMetadata();
    QueryFactory qf = new QueryFactory();
    // Export the MdBusinesses that define the hierarchy attributes
    BusinessDAOQuery uQ = qf.businessDAOQuery(Universal.CLASS);
    BusinessDAOQuery mdbQ = qf.businessDAOQuery(MdBusiness.CLASS);
    mdbQ.WHERE(mdbQ.aUUID(MdBusiness.OID).EQ(uQ.aReference(Universal.MDBUSINESS).aUUID(Universal.OID)));
    OIterator<? extends BusinessDAOIF> mdbI = mdbQ.getIterator();
    try {
        while (mdbI.hasNext()) {
            MdBusinessDAOIF mdBusiness = (MdBusinessDAOIF) mdbI.next();
            System.out.println(mdBusiness.getType() + "  " + mdBusiness.getTypeName());
            exportMetadata.addCreateOrUpdate(mdBusiness);
        }
    } finally {
        mdbI.close();
    }
    // Export the Universals
    uQ = qf.businessDAOQuery(Universal.CLASS);
    OIterator<? extends BusinessDAOIF> uQI = uQ.getIterator();
    try {
        while (uQI.hasNext()) {
            BusinessDAOIF businessDAOIF = (BusinessDAOIF) uQI.next();
            System.out.println(businessDAOIF.getType() + "  " + businessDAOIF.getKey());
            exportMetadata.addCreateOrUpdate(businessDAOIF);
        }
    } finally {
        mdbI.close();
    }
    // Export the MdTermRelationships that involve universals
    List<MdTermRelationshipDAOIF> universalRelList = getUniversalRelationships();
    for (MdTermRelationshipDAOIF mdTermRelationshipDAOIF : universalRelList) {
        System.out.println(mdTermRelationshipDAOIF.getType() + "  " + mdTermRelationshipDAOIF.getKey());
        exportMetadata.addCreateOrUpdate(mdTermRelationshipDAOIF);
    }
    // Export the instances of the relationships between the universals.
    for (MdTermRelationshipDAOIF mdTermRelationshipDAOIF : universalRelList) {
        RelationshipDAOQuery relQ = qf.relationshipDAOQuery(mdTermRelationshipDAOIF.definesType());
        OIterator<RelationshipDAOIF> relI = relQ.getIterator();
        try {
            while (relI.hasNext()) {
                RelationshipDAOIF relationshipDAOIF = relI.next();
                exportMetadata.addCreateOrUpdate(relationshipDAOIF);
            }
        } finally {
            relI.close();
        }
    }
    List<MdTermRelationshipDAOIF> geoEntityRelList = getGeoEntityRelationships();
    for (MdTermRelationshipDAOIF mdTermRelationshipDAOIF : geoEntityRelList) {
        System.out.println(mdTermRelationshipDAOIF.getType() + "  " + mdTermRelationshipDAOIF.getKey());
        exportMetadata.addCreateOrUpdate(mdTermRelationshipDAOIF);
    }
    VersionExporter.export(fileName, schemaLocation, exportMetadata);
// FileInstanceExporter.export(fileName, schemaLocation, queries, _exportOnlyModifiedAttributes);
}
Also used : MdTermRelationshipDAOIF(com.runwaysdk.dataaccess.MdTermRelationshipDAOIF) ExportMetadata(com.runwaysdk.dataaccess.io.dataDefinition.ExportMetadata) QueryFactory(com.runwaysdk.query.QueryFactory) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) MdTermRelationshipDAOIF(com.runwaysdk.dataaccess.MdTermRelationshipDAOIF) RelationshipDAOIF(com.runwaysdk.dataaccess.RelationshipDAOIF) RelationshipDAOQuery(com.runwaysdk.query.RelationshipDAOQuery) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) BusinessDAOQuery(com.runwaysdk.query.BusinessDAOQuery) Request(com.runwaysdk.session.Request)

Example 2 with BusinessDAOIF

use of com.runwaysdk.dataaccess.BusinessDAOIF in project geoprism-registry by terraframe.

the class ListTypeVersionRequiredDefaults method dotItInTrans.

@Transaction
private void dotItInTrans() {
    BusinessDAOQuery query = new QueryFactory().businessDAOQuery(ListTypeVersion.CLASS);
    query.WHERE(query.aBoolean(ListTypeVersion.WORKING).EQ(true));
    query.AND(query.aCharacter(ListTypeVersion.LISTVISIBILITY).EQ((String) null).OR(query.aCharacter(ListTypeVersion.GEOSPATIALVISIBILITY).EQ((String) null)));
    logger.info("About to patch " + query.getCount() + " ListTypeVersions with default values for visiblity.");
    OIterator<BusinessDAOIF> it = query.getIterator();
    try {
        while (it.hasNext()) {
            BusinessDAO version = (BusinessDAO) it.next();
            if (version.getValue(ListTypeVersion.LISTVISIBILITY) == null || version.getValue(ListTypeVersion.LISTVISIBILITY).length() == 0) {
                version.setValue(ListTypeVersion.LISTVISIBILITY, ListType.PRIVATE);
            }
            if (version.getValue(ListTypeVersion.GEOSPATIALVISIBILITY) == null || version.getValue(ListTypeVersion.GEOSPATIALVISIBILITY).length() == 0) {
                version.setValue(ListTypeVersion.GEOSPATIALVISIBILITY, ListType.PRIVATE);
            }
            version.apply();
        }
    } finally {
        it.close();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) BusinessDAOQuery(com.runwaysdk.query.BusinessDAOQuery) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with BusinessDAOIF

use of com.runwaysdk.dataaccess.BusinessDAOIF 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 4 with BusinessDAOIF

use of com.runwaysdk.dataaccess.BusinessDAOIF in project geoprism-registry by terraframe.

the class HierarchyExporter method exportUniversalInstances.

/**
 * Export all instances of the given {@link Universal} type.
 *
 * @param universal
 */
private static void exportUniversalInstances(ExportMetadata exportMetadata, Universal universal) {
    boolean isLeafType = universal.getIsLeafType();
    MdBusiness mdBusiness = universal.getMdBusiness();
    QueryFactory qf = new QueryFactory();
    BusinessDAOQuery q = qf.businessDAOQuery(mdBusiness.definesType());
    System.out.println("\nExporting Universal [" + universal.getUniversalId() + "] instances:");
    System.out.println("-----------------------------------------------------------------------");
    int counter = 0;
    OIterator<BusinessDAOIF> i = q.getIterator();
    try {
        for (BusinessDAOIF businessDAOIF : i) {
            if (!isLeafType) {
                BusinessDAOIF geoEntity = ((AttributeReferenceIF) businessDAOIF.getAttributeIF(RegistryConstants.GEO_ENTITY_ATTRIBUTE_NAME)).dereference();
                exportMetadata.addCreate(geoEntity);
            }
            exportMetadata.addCreate(businessDAOIF);
            System.out.print(".");
            if (counter % 100 == 0) {
                System.out.println();
            }
            counter++;
        }
    } finally {
        i.close();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) BusinessDAOIF(com.runwaysdk.dataaccess.BusinessDAOIF) BusinessDAOQuery(com.runwaysdk.query.BusinessDAOQuery) AttributeReferenceIF(com.runwaysdk.dataaccess.AttributeReferenceIF)

Aggregations

BusinessDAOIF (com.runwaysdk.dataaccess.BusinessDAOIF)4 QueryFactory (com.runwaysdk.query.QueryFactory)4 BusinessDAOQuery (com.runwaysdk.query.BusinessDAOQuery)3 BusinessDAO (com.runwaysdk.dataaccess.BusinessDAO)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 Request (com.runwaysdk.session.Request)2 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)2 AttributeDoesNotExistException (com.runwaysdk.dataaccess.AttributeDoesNotExistException)1 AttributeReferenceIF (com.runwaysdk.dataaccess.AttributeReferenceIF)1 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)1 MdTermRelationshipDAOIF (com.runwaysdk.dataaccess.MdTermRelationshipDAOIF)1 RelationshipDAOIF (com.runwaysdk.dataaccess.RelationshipDAOIF)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1 ExportMetadata (com.runwaysdk.dataaccess.io.dataDefinition.ExportMetadata)1 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)1 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)1 OIterator (com.runwaysdk.query.OIterator)1 RelationshipDAOQuery (com.runwaysdk.query.RelationshipDAOQuery)1 AllowedIn (com.runwaysdk.system.gis.geo.AllowedIn)1