Search in sources :

Example 26 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesMandatory.

@Test
void testValidateMetadataAttributeValuesMandatory() throws IOException {
    defaultSetupWithAttributes();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_mandatory_attributes.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    TypeReport typeReport = validationReport.getTypeReport(DataElement.class);
    assertNotNull(typeReport);
    assertEquals(4, typeReport.getObjectReportsCount());
    typeReport.forEachObjectReport(objectReport -> assertEquals(2, objectReport.getErrorReportsCount()));
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) TypeReport(org.hisp.dhis.feedback.TypeReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Example 27 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class UserControllerTest method createReportWith.

private ImportReport createReportWith(Status status, Consumer<Stats> operation) {
    TypeReport typeReport = new TypeReport(User.class);
    operation.accept(typeReport.getStats());
    ImportReport report = new ImportReport();
    report.setStatus(status);
    report.addTypeReport(typeReport);
    return report;
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport)

Example 28 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class DefaultObjectBundleService method handleCreates.

//-----------------------------------------------------------------------------------
// Utility Methods
//-----------------------------------------------------------------------------------
private TypeReport handleCreates(Session session, Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects.isEmpty()) {
        return typeReport;
    }
    String message = "(" + bundle.getUsername() + ") Creating " + objects.size() + " object(s) of type " + objects.get(0).getClass().getSimpleName();
    log.info(message);
    if (bundle.hasTaskId()) {
        notifier.notify(bundle.getTaskId(), message);
    }
    objects.forEach(object -> objectBundleHooks.forEach(hook -> hook.preCreate(object, bundle)));
    for (int idx = 0; idx < objects.size(); idx++) {
        IdentifiableObject object = objects.get(idx);
        if (Preheat.isDefault(object))
            continue;
        ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
        objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
        typeReport.addObjectReport(objectReport);
        preheatService.connectReferences(object, bundle.getPreheat(), bundle.getPreheatIdentifier());
        session.save(object);
        if (MetadataObject.class.isInstance(object)) {
            deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery(object));
        }
        bundle.getPreheat().replace(bundle.getPreheatIdentifier(), object);
        objectBundleHooks.forEach(hook -> hook.postCreate(object, bundle));
        if (log.isDebugEnabled()) {
            String msg = "(" + bundle.getUsername() + ") Created object '" + bundle.getPreheatIdentifier().getIdentifiersWithName(object) + "'";
            log.debug(msg);
        }
        if (FlushMode.OBJECT == bundle.getFlushMode())
            session.flush();
    }
    return typeReport;
}
Also used : HibernateCacheManager(org.hisp.dhis.cache.HibernateCacheManager) PreheatService(org.hisp.dhis.preheat.PreheatService) IdentifiableObjectUtils(org.hisp.dhis.common.IdentifiableObjectUtils) MergeService(org.hisp.dhis.schema.MergeService) Session(org.hibernate.Session) Preheat(org.hisp.dhis.preheat.Preheat) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) MergeParams(org.hisp.dhis.schema.MergeParams) FlushMode(org.hisp.dhis.dxf2.metadata.FlushMode) TypeReport(org.hisp.dhis.feedback.TypeReport) ArrayList(java.util.ArrayList) Notifier(org.hisp.dhis.system.notification.Notifier) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DeletedObjectService(org.hisp.dhis.deletedobject.DeletedObjectService) SessionFactory(org.hibernate.SessionFactory) SchemaService(org.hisp.dhis.schema.SchemaService) MergeMode(org.hisp.dhis.common.MergeMode) DeletedObjectQuery(org.hisp.dhis.deletedobject.DeletedObjectQuery) PreheatParams(org.hisp.dhis.preheat.PreheatParams) List(java.util.List) CurrentUserService(org.hisp.dhis.user.CurrentUserService) MetadataObject(org.hisp.dhis.common.MetadataObject) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Transactional(org.springframework.transaction.annotation.Transactional) TypeReport(org.hisp.dhis.feedback.TypeReport) DeletedObjectQuery(org.hisp.dhis.deletedobject.DeletedObjectQuery) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 29 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class DefaultObjectBundleService method handleUpdates.

private TypeReport handleUpdates(Session session, Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects.isEmpty()) {
        return typeReport;
    }
    String message = "(" + bundle.getUsername() + ") Updating " + objects.size() + " object(s) of type " + objects.get(0).getClass().getSimpleName();
    log.info(message);
    if (bundle.hasTaskId()) {
        notifier.notify(bundle.getTaskId(), message);
    }
    objects.forEach(object -> {
        IdentifiableObject persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
        objectBundleHooks.forEach(hook -> hook.preUpdate(object, persistedObject, bundle));
    });
    for (int idx = 0; idx < objects.size(); idx++) {
        IdentifiableObject object = objects.get(idx);
        IdentifiableObject persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
        if (Preheat.isDefault(object))
            continue;
        ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
        objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
        typeReport.addObjectReport(objectReport);
        preheatService.connectReferences(object, bundle.getPreheat(), bundle.getPreheatIdentifier());
        if (bundle.getMergeMode() != MergeMode.NONE) {
            mergeService.merge(new MergeParams<>(object, persistedObject).setMergeMode(bundle.getMergeMode()).setSkipSharing(bundle.isSkipSharing()));
        }
        session.update(persistedObject);
        if (MetadataObject.class.isInstance(object)) {
            deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery(object));
        }
        objectBundleHooks.forEach(hook -> hook.postUpdate(persistedObject, bundle));
        bundle.getPreheat().replace(bundle.getPreheatIdentifier(), persistedObject);
        if (log.isDebugEnabled()) {
            String msg = "(" + bundle.getUsername() + ") Updated object '" + bundle.getPreheatIdentifier().getIdentifiersWithName(persistedObject) + "'";
            log.debug(msg);
        }
        if (FlushMode.OBJECT == bundle.getFlushMode())
            session.flush();
    }
    return typeReport;
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport) DeletedObjectQuery(org.hisp.dhis.deletedobject.DeletedObjectQuery) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 30 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class DefaultObjectBundleValidationService method checkDuplicateIds.

private TypeReport checkDuplicateIds(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> persistedObjects, List<IdentifiableObject> nonPersistedObjects, Preheat preheat, PreheatIdentifier identifier) {
    TypeReport typeReport = new TypeReport(klass);
    if (persistedObjects.isEmpty() && nonPersistedObjects.isEmpty()) {
        return typeReport;
    }
    Map<Class<?>, String> idMap = new HashMap<>();
    Iterator<IdentifiableObject> iterator = persistedObjects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        if (idMap.containsKey(object.getClass()) && idMap.get(object.getClass()).equals(object.getUid())) {
            ErrorReport errorReport = new ErrorReport(object.getClass(), ErrorCode.E5004, object.getUid(), object.getClass()).setMainId(object.getUid()).setErrorProperty("id");
            ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReport(errorReport);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        } else {
            idMap.put(object.getClass(), object.getUid());
        }
        idx++;
    }
    iterator = nonPersistedObjects.iterator();
    idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        if (idMap.containsKey(object.getClass()) && idMap.get(object.getClass()).equals(object.getUid())) {
            ErrorReport errorReport = new ErrorReport(object.getClass(), ErrorCode.E5004, object.getUid(), object.getClass()).setMainId(object.getUid()).setErrorProperty("id");
            ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReport(errorReport);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        } else {
            idMap.put(object.getClass(), object.getUid());
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) HashMap(java.util.HashMap) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

TypeReport (org.hisp.dhis.feedback.TypeReport)52 ObjectReport (org.hisp.dhis.feedback.ObjectReport)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)24 ErrorReport (org.hisp.dhis.feedback.ErrorReport)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)13 List (java.util.List)7 Test (org.junit.jupiter.api.Test)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)5 ObjectBundleCommitReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport)5 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)5 User (org.hisp.dhis.user.User)5 HashMap (java.util.HashMap)4 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 SchemaService (org.hisp.dhis.schema.SchemaService)4 Service (org.springframework.stereotype.Service)4 AllArgsConstructor (lombok.AllArgsConstructor)3 Session (org.hibernate.Session)3 MergeParams (org.hisp.dhis.schema.MergeParams)3