Search in sources :

Example 96 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction 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 97 with Transaction

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

the class OrganizationConverter method create.

@Transaction
public Organization create(OrganizationDTO organizationDTO) {
    final Organization organization = this.fromDTO(organizationDTO);
    ServiceFactory.getOrganizationPermissionService().enforceActorCanCreate();
    organization.apply();
    return organization;
}
Also used : Organization(net.geoprism.registry.Organization) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 98 with Transaction

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

the class OrganizationConverter method update.

@Transaction
public Organization update(OrganizationDTO organizationDTO) {
    Organization organization = Organization.getByKey(organizationDTO.getCode());
    ServiceFactory.getOrganizationPermissionService().enforceActorCanUpdate();
    organization.lock();
    organization.setCode(organizationDTO.getCode());
    populate(organization.getDisplayLabel(), organizationDTO.getLabel());
    populate(organization.getContactInfo(), organizationDTO.getContactInfo());
    organization.apply();
    organization.unlock();
    return organization;
}
Also used : Organization(net.geoprism.registry.Organization) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 99 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction 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 100 with Transaction

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

the class ServerGeoObjectTypeConverter method createDefaultAttributes.

/**
 * Adds default attributes to the given {@link MdBusinessDAO} according to the
 * Common Geo-Registry specification for {@link GeoObject}.
 *
 * @param mdBusinessDAO
 *          {@link MdBusinessDAO} that will define the default attributes.
 */
@Transaction
public void createDefaultAttributes(Universal universal, MdBusiness definingMdBusiness) {
    if (!universal.getIsLeafType()) {
    // MdAttributeReference geoEntRefMdAttrRef = new MdAttributeReference();
    // geoEntRefMdAttrRef.setAttributeName(RegistryConstants.GEO_ENTITY_ATTRIBUTE_NAME);
    // geoEntRefMdAttrRef.getDisplayLabel().setValue(RegistryConstants.GEO_ENTITY_ATTRIBUTE_LABEL);
    // geoEntRefMdAttrRef.getDescription().setValue("References a GeoEntity
    // for non-leaf Universal Types");
    // geoEntRefMdAttrRef.setMdBusiness(mdBusGeoEntity);
    // geoEntRefMdAttrRef.setDefiningMdClass(definingMdBusiness);
    // geoEntRefMdAttrRef.setRequired(false);
    // geoEntRefMdAttrRef.apply();
    }
    // DefaultAttribute.UID - Defined on the MdBusiness and the values are from
    // the {@code GeoObject#OID};
    MdAttributeUUID uuidMdAttr = new MdAttributeUUID();
    uuidMdAttr.setAttributeName(RegistryConstants.UUID);
    uuidMdAttr.getDisplayLabel().setValue(RegistryConstants.UUID_LABEL);
    uuidMdAttr.getDescription().setValue("The universal unique identifier of the feature.");
    uuidMdAttr.setDefiningMdClass(definingMdBusiness);
    uuidMdAttr.setRequired(true);
    uuidMdAttr.addIndexType(MdAttributeIndices.UNIQUE_INDEX);
    uuidMdAttr.apply();
    // DefaultAttribute.TYPE - This is the display label of the Universal.
    // BusObject.mdBusiness.Universal.displayLabel
    // DefaultAttribute.CREATED_DATE - The create data on the Business Object?
    // DefaultAttribute.UPDATED_DATE - The update data on the Business Object?
    // DefaultAttribute.STATUS
    MdAttributeBooleanDAO invalidMdAttr = MdAttributeBooleanDAO.newInstance();
    invalidMdAttr.setValue(MdAttributeConcreteInfo.NAME, DefaultAttribute.INVALID.getName());
    invalidMdAttr.setStructValue(MdAttributeConcreteInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.INVALID.getDefaultLocalizedName());
    invalidMdAttr.setStructValue(MdAttributeConcreteInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, DefaultAttribute.INVALID.getDefaultDescription());
    invalidMdAttr.setValue(MdAttributeConcreteInfo.DEFINING_MD_CLASS, definingMdBusiness.getOid());
    invalidMdAttr.setValue(MdAttributeConcreteInfo.REQUIRED, MdAttributeBooleanInfo.TRUE);
    invalidMdAttr.setValue(MdAttributeConcreteInfo.DEFAULT_VALUE, MdAttributeBooleanInfo.FALSE);
    invalidMdAttr.addItem(MdAttributeConcreteInfo.INDEX_TYPE, IndexTypes.NON_UNIQUE_INDEX.getOid());
    invalidMdAttr.apply();
}
Also used : MdAttributeUUID(com.runwaysdk.system.metadata.MdAttributeUUID) MdAttributeBooleanDAO(com.runwaysdk.dataaccess.metadata.MdAttributeBooleanDAO) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)131 QueryFactory (com.runwaysdk.query.QueryFactory)29 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)17 Date (java.util.Date)15 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)15 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)14 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)13 LinkedList (java.util.LinkedList)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)10 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)10 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)10 List (java.util.List)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexObject (com.runwaysdk.business.graph.VertexObject)8 IOException (java.io.IOException)8 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)8 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)8 JSONObject (org.json.JSONObject)8