Search in sources :

Example 1 with BusinessDAO

use of com.runwaysdk.dataaccess.BusinessDAO 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 2 with BusinessDAO

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

the class LocalizeListMetadataFieldsPatch method migrateExistingLists.

private void migrateExistingLists() {
    MasterListQuery mlq = new MasterListQuery(new QueryFactory());
    logger.info("Migrating metadata for " + mlq.getCount() + " existing lists.");
    try (OIterator<? extends MasterList> it = mlq.getIterator()) {
        while (it.hasNext()) {
            MasterList list = it.next();
            BusinessDAO listDAO = (BusinessDAO) BusinessFacade.getEntityDAO(list);
            list.getDescriptionLocal().setDefaultValue(listDAO.getValue(LISTABSTRACT));
            list.getProcessLocal().setDefaultValue(listDAO.getValue(PROCESS));
            list.getProgressLocal().setDefaultValue(listDAO.getValue(PROGRESS));
            list.getAccessConstraintsLocal().setDefaultValue(listDAO.getValue(ACCESSCONSTRAINTS));
            list.getUseConstraintsLocal().setDefaultValue(listDAO.getValue(USECONSTRAINTS));
            list.getAcknowledgementsLocal().setDefaultValue(listDAO.getValue(ACKNOWLEDGEMENTS));
            list.getDisclaimerLocal().setDefaultValue(listDAO.getValue(DISCLAIMER));
            list.apply();
        }
    }
}
Also used : MasterListQuery(net.geoprism.registry.MasterListQuery) QueryFactory(com.runwaysdk.query.QueryFactory) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MasterList(net.geoprism.registry.MasterList)

Example 3 with BusinessDAO

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

the class PatchExistsAndInvalid method patchMasterlistVersions.

private void patchMasterlistVersions() {
    final Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    MasterListVersionQuery query = new MasterListVersionQuery(new QueryFactory());
    try (OIterator<? extends MasterListVersion> it = query.getIterator()) {
        for (MasterListVersion version : it) {
            // ServerGeoObjectType type = version.getMasterlist().getGeoObjectType();
            // We are accessing it in this weird way because MasterList was changed to have new localized attributes. If we run this patch
            // before masterlist is patched then simply instantiating a MasterList object will throw an error when it tries to load the structs.
            BusinessDAO versionDAO = (BusinessDAO) BusinessDAO.get(version.getOid());
            String masterListOid = versionDAO.getValue(MasterListVersion.MASTERLIST);
            BusinessDAO masterListDAO = (BusinessDAO) BusinessDAO.get(masterListOid);
            String universalOid = masterListDAO.getValue(MasterList.UNIVERSAL);
            ServerGeoObjectType type = ServerGeoObjectType.get(Universal.get(universalOid));
            // Patch metadata
            // AttributeType existsAttr = type.getAttribute(DefaultAttribute.EXISTS.getName()).get();
            // MasterListVersion.createMdAttributeFromAttributeType(version, type, existsAttr, locales);
            AttributeType invalidAttr = type.getAttribute(DefaultAttribute.INVALID.getName()).get();
            MasterListVersion.createMdAttributeFromAttributeType(version, type, invalidAttr, locales);
            // Instance data is too hard to patch. We're just going to republish all the lists
            logger.info("Master list version [" + version.getKey() + "] has been queued for republishing.");
            PublishMasterListVersionJob job = new PublishMasterListVersionJob();
            job.setMasterListVersion(version);
            job.setMasterListId(masterListOid);
            job.apply();
            // job.start();
            // JobHistory history = job.createNewHistory();
            JobHistory history = new JobHistory();
            history.setStartTime(new Date());
            history.addStatus(AllJobStatus.QUEUED);
            history.apply();
            JobHistoryRecord record = new JobHistoryRecord(job, history);
            record.apply();
        }
    }
}
Also used : Locale(java.util.Locale) QueryFactory(com.runwaysdk.query.QueryFactory) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) JobHistory(com.runwaysdk.system.scheduler.JobHistory) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MasterListVersion(net.geoprism.registry.MasterListVersion) PublishMasterListVersionJob(net.geoprism.registry.etl.PublishMasterListVersionJob) Date(java.util.Date) MasterListVersionQuery(net.geoprism.registry.MasterListVersionQuery) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) JobHistoryRecord(com.runwaysdk.system.scheduler.JobHistoryRecord)

Example 4 with BusinessDAO

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

the class PatchTerms method doIt.

@Transaction
private void doIt() {
    ClassifierQuery gQuery = new ClassifierQuery(new QueryFactory());
    Classifier clazz = this.getByClassifierId("CLASS");
    BusinessDAO clazzDAO = BusinessDAO.get(clazz.getOid()).getBusinessDAO();
    clazzDAO.setValue(Classifier.CLASSIFIERPACKAGE, RegistryConstants.REGISTRY_PACKAGE);
    clazzDAO.setValue(Classifier.KEYNAME, "CLASS");
    clazzDAO.apply();
    Classifier root = this.getByClassifierId("ROOT");
    BusinessDAO rootDAO = BusinessDAO.get(root.getOid()).getBusinessDAO();
    rootDAO.setValue(Classifier.CLASSIFIERPACKAGE, "ROOT");
    rootDAO.setValue(Classifier.KEYNAME, "ROOT");
    rootDAO.apply();
    try (OIterator<? extends Classifier> it = gQuery.getIterator()) {
        while (it.hasNext()) {
            Classifier classifier = it.next();
            LinkedList<Term> parents = new LinkedList<>(GeoEntityUtil.getOrderedAncestors(root, classifier, ClassifierIsARelationship.CLASS));
            Collections.reverse(parents);
            // Root -> Class Root -> Class -> Attribute -> Option
            if (parents.size() == 4) {
                Iterator<Term> pit = parents.iterator();
                // while (pit.hasNext())
                // {
                // Classifier p = (Classifier) pit.next();
                // 
                // // logger.error("[" + p.getClassifierId() + "]: ");
                // System.out.println(" Parent [" + p.getClassifierId() + "]: ");
                // }
                pit = parents.iterator();
                pit.next();
                Classifier parent = (Classifier) pit.next();
                classifier.appLock();
                classifier.setClassifierPackage(parent.getKey());
                classifier.setKeyName(Classifier.buildKey(parent.getKey(), classifier.getClassifierId()));
                classifier.apply();
            } else if (!(classifier.getOid().equals(clazz.getOid()) || classifier.getOid().equals(root.getOid()))) {
                classifier.appLock();
                classifier.setClassifierPackage(RegistryConstants.REGISTRY_PACKAGE);
                classifier.setKeyName(Classifier.buildKey(RegistryConstants.REGISTRY_PACKAGE, classifier.getClassifierId()));
                classifier.apply();
            }
        }
    }
}
Also used : ClassifierQuery(net.geoprism.ontology.ClassifierQuery) QueryFactory(com.runwaysdk.query.QueryFactory) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) Classifier(net.geoprism.ontology.Classifier) Term(com.runwaysdk.business.ontology.Term) LinkedList(java.util.LinkedList) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 5 with BusinessDAO

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

the class AttributeTypeConverter method build.

public AttributeType build(MdAttributeConcreteDAOIF mdAttribute) {
    Locale locale = Session.getCurrentLocale();
    String attributeName = mdAttribute.definesAttribute();
    LocalizedValue displayLabel = AttributeTypeConverter.convert(mdAttribute.getDisplayLabel(locale), mdAttribute.getDisplayLabels());
    LocalizedValue description = AttributeTypeConverter.convert(mdAttribute.getDescription(locale), mdAttribute.getDescriptions());
    boolean required = mdAttribute.isRequired();
    boolean unique = mdAttribute.isUnique();
    boolean isChangeOverTime = true;
    DefaultAttribute defaultAttr = DefaultAttribute.getByAttributeName(attributeName);
    if (defaultAttr != null) {
        isChangeOverTime = defaultAttr.isChangeOverTime();
    }
    if (mdAttribute instanceof MdAttributeBooleanDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeBooleanType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeLocalDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeLocalType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeCharacterDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeCharacterType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDateDAOIF || mdAttribute instanceof MdAttributeDateTimeDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeDateType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeDecDAOIF) {
        MdAttributeDecDAOIF mdAttributeDec = (MdAttributeDecDAOIF) mdAttribute;
        AttributeFloatType attributeType = (AttributeFloatType) AttributeType.factory(attributeName, displayLabel, description, AttributeFloatType.TYPE, required, unique, isChangeOverTime);
        attributeType.setPrecision(Integer.parseInt(mdAttributeDec.getLength()));
        attributeType.setScale(Integer.parseInt(mdAttributeDec.getDecimal()));
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeIntegerDAOIF || mdAttribute instanceof MdAttributeLongDAOIF) {
        return AttributeType.factory(attributeName, displayLabel, description, AttributeIntegerType.TYPE, required, unique, isChangeOverTime);
    } else if (mdAttribute instanceof MdAttributeClassificationDAOIF) {
        MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
        AttributeClassificationType attributeType = (AttributeClassificationType) AttributeType.factory(attributeName, displayLabel, description, AttributeClassificationType.TYPE, required, unique, isChangeOverTime);
        attributeType.setClassificationType(mdClassification.getValue(MdClassificationInfo.TYPE_NAME));
        String rootOid = ((MdAttributeClassificationDAOIF) mdAttribute).getValue(MdAttributeClassificationInfo.ROOT);
        if (rootOid != null && rootOid.length() > 0) {
            ClassificationType type = new ClassificationType(mdClassification);
            Classification classification = Classification.getByOid(type, rootOid);
            attributeType.setRootTerm(classification.toTerm());
        }
        return attributeType;
    } else if (mdAttribute instanceof MdAttributeEnumerationDAOIF || mdAttribute instanceof MdAttributeTermDAOIF) {
        AttributeTermType attributeType = (AttributeTermType) AttributeType.factory(attributeName, displayLabel, description, AttributeTermType.TYPE, required, unique, isChangeOverTime);
        if (mdAttribute instanceof MdAttributeTermDAOIF) {
            List<RelationshipDAOIF> rels = ((MdAttributeTermDAOIF) mdAttribute).getAllAttributeRoots();
            if (rels.size() > 0) {
                RelationshipDAOIF rel = rels.get(0);
                BusinessDAO classy = (BusinessDAO) rel.getChild();
                TermConverter termBuilder = new TermConverter(classy.getKey());
                Term adapterTerm = termBuilder.build();
                attributeType.setRootTerm(adapterTerm);
            } else {
                throw new ProgrammingErrorException("Expected an attribute root on MdAttribute [" + mdAttribute.getKey() + "].");
            }
        } else {
            throw new ProgrammingErrorException("Enum attributes are not supported at this time.");
        }
        return attributeType;
    }
    throw new UnsupportedOperationException("Unsupported attribute type [" + mdAttribute.getClass().getSimpleName() + "]");
}
Also used : Locale(java.util.Locale) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) RelationshipDAOIF(com.runwaysdk.dataaccess.RelationshipDAOIF) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeEnumerationDAOIF(com.runwaysdk.dataaccess.MdAttributeEnumerationDAOIF) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) Classification(net.geoprism.registry.model.Classification) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) List(java.util.List) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) BusinessDAO(com.runwaysdk.dataaccess.BusinessDAO) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeLocalDAOIF(com.runwaysdk.dataaccess.MdAttributeLocalDAOIF) MdAttributeDecDAOIF(com.runwaysdk.dataaccess.MdAttributeDecDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) MdAttributeClassificationDAOIF(com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF)

Aggregations

BusinessDAO (com.runwaysdk.dataaccess.BusinessDAO)5 QueryFactory (com.runwaysdk.query.QueryFactory)4 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 Locale (java.util.Locale)2 Term (com.runwaysdk.business.ontology.Term)1 BusinessDAOIF (com.runwaysdk.dataaccess.BusinessDAOIF)1 MdAttributeBooleanDAOIF (com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF)1 MdAttributeCharacterDAOIF (com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF)1 MdAttributeClassificationDAOIF (com.runwaysdk.dataaccess.MdAttributeClassificationDAOIF)1 MdAttributeDateDAOIF (com.runwaysdk.dataaccess.MdAttributeDateDAOIF)1 MdAttributeDateTimeDAOIF (com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF)1 MdAttributeDecDAOIF (com.runwaysdk.dataaccess.MdAttributeDecDAOIF)1 MdAttributeEnumerationDAOIF (com.runwaysdk.dataaccess.MdAttributeEnumerationDAOIF)1 MdAttributeIntegerDAOIF (com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF)1 MdAttributeLocalDAOIF (com.runwaysdk.dataaccess.MdAttributeLocalDAOIF)1 MdAttributeLongDAOIF (com.runwaysdk.dataaccess.MdAttributeLongDAOIF)1 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)1 MdClassificationDAOIF (com.runwaysdk.dataaccess.MdClassificationDAOIF)1 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 RelationshipDAOIF (com.runwaysdk.dataaccess.RelationshipDAOIF)1