Search in sources :

Example 11 with TypeReport

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

the class DefaultObjectBundleValidationService method checkUniqueAttributes.

private TypeReport checkUniqueAttributes(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier) {
    TypeReport typeReport = new TypeReport(klass);
    Schema schema = schemaService.getDynamicSchema(klass);
    if (objects.isEmpty() || !schema.havePersistedProperty("attributeValues")) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        List<ErrorReport> errorReports = checkUniqueAttributes(klass, object, preheat, identifier);
        if (!errorReports.isEmpty()) {
            ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReports(errorReports);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) Schema(org.hisp.dhis.schema.Schema) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 12 with TypeReport

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

the class DefaultObjectBundleValidationService method runValidationHooks.

private TypeReport runValidationHooks(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects == null || objects.isEmpty()) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        List<ErrorReport> errorReports = new ArrayList<>();
        objectBundleHooks.forEach(hook -> errorReports.addAll(hook.validate(object, bundle)));
        if (!errorReports.isEmpty()) {
            ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReports(errorReports);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
            continue;
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ArrayList(java.util.ArrayList) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 13 with TypeReport

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

the class DefaultObjectBundleValidationService method validateForCreate.

private TypeReport validateForCreate(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects == null || objects.isEmpty()) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject identifiableObject = iterator.next();
        IdentifiableObject object = bundle.getPreheat().get(bundle.getPreheatIdentifier(), identifiableObject);
        if (object != null && object.getId() > 0) {
            ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReport(new ErrorReport(klass, ErrorCode.E5000, bundle.getPreheatIdentifier(), bundle.getPreheatIdentifier().getIdentifiersWithName(identifiableObject)).setMainId(identifiableObject.getUid()));
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 14 with TypeReport

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

the class ObjectBundleValidationReport method addTypeReport.

public void addTypeReport(TypeReport report) {
    if (report == null)
        return;
    if (!typeReportMap.containsKey(report.getKlass())) {
        typeReportMap.put(report.getKlass(), report);
        return;
    }
    TypeReport typeReport = typeReportMap.get(report.getKlass());
    typeReport.merge(typeReport);
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport)

Example 15 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)

Aggregations

TypeReport (org.hisp.dhis.feedback.TypeReport)25 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)16 ObjectReport (org.hisp.dhis.feedback.ObjectReport)16 ErrorReport (org.hisp.dhis.feedback.ErrorReport)12 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)11 ObjectBundleCommitReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport)5 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 User (org.hisp.dhis.user.User)3 Test (org.junit.Test)3 Session (org.hibernate.Session)2 SystemTimer (org.hisp.dhis.commons.timer.SystemTimer)2 Timer (org.hisp.dhis.commons.timer.Timer)2 DeletedObjectQuery (org.hisp.dhis.deletedobject.DeletedObjectQuery)2 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)2 Schema (org.hisp.dhis.schema.Schema)2 List (java.util.List)1 Map (java.util.Map)1 Log (org.apache.commons.logging.Log)1