Search in sources :

Example 96 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class MetadataSyncImportHandler method importMetadata.

public MetadataSyncSummary importMetadata(MetadataSyncParams syncParams, String versionSnapShot) {
    MetadataVersion version = getMetadataVersion(syncParams);
    MetadataImportParams importParams = syncParams.getImportParams();
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    if (importParams == null) {
        throw new MetadataSyncServiceException("MetadataImportParams for the Sync cant be null.");
    }
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> classListMap = parseClassListMap(versionSnapShot);
    if (classListMap == null) {
        throw new MetadataSyncServiceException("ClassListMap can't be null");
    }
    importParams.setObjects(classListMap);
    ImportReport importReport = null;
    try {
        importReport = metadataImportService.importMetadata(importParams);
    } catch (Exception e) {
        String message = "Exception occurred while trying to import the metadata. " + e.getMessage();
        log.error(message, e);
        throw new MetadataSyncImportException(message, e);
    }
    boolean addNewVersion = handleImportReport(importReport, version);
    if (addNewVersion) {
        try {
            metadataVersionDelegate.addNewMetadataVersion(version);
        } catch (MetadataVersionServiceException e) {
            throw new MetadataSyncServiceException(e.getMessage(), e);
        }
    }
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.setMetadataVersion(version);
    return metadataSyncSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) IOException(java.io.IOException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) List(java.util.List)

Example 97 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class UserRoleObjectBundleHook method postCommit.

@Override
@SuppressWarnings("unchecked")
public void postCommit(ObjectBundle bundle) {
    if (!bundle.getObjectMap().containsKey(UserAuthorityGroup.class))
        return;
    List<IdentifiableObject> objects = bundle.getObjectMap().get(UserAuthorityGroup.class);
    Map<String, Map<String, Object>> userRoleReferences = bundle.getObjectReferences(UserAuthorityGroup.class);
    if (userRoleReferences == null || userRoleReferences.isEmpty()) {
        return;
    }
    for (IdentifiableObject object : objects) {
        object = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
        Map<String, Object> userRoleReferenceMap = userRoleReferences.get(object.getUid());
        if (userRoleReferenceMap == null || userRoleReferenceMap.isEmpty()) {
            continue;
        }
        UserAuthorityGroup userRole = (UserAuthorityGroup) object;
        userRole.setDataSets((Set<DataSet>) userRoleReferenceMap.get("dataSets"));
        userRole.setPrograms((Set<Program>) userRoleReferenceMap.get("programs"));
        preheatService.connectReferences(userRole, bundle.getPreheat(), bundle.getPreheatIdentifier());
        sessionFactory.getCurrentSession().update(userRole);
    }
}
Also used : Program(org.hisp.dhis.program.Program) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Map(java.util.Map) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 98 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class AbstractGridView method renderMergedOutputModel.

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Object object = model.get("model");
    List<Grid> grids = new ArrayList<>();
    if (WebMetadata.class.isAssignableFrom(object.getClass())) {
        WebMetadata metadata = (WebMetadata) object;
        Collection<Field> fields = ReflectionUtils.collectFields(WebMetadata.class, PredicateUtils.idObjectCollections);
        for (Field field : fields) {
            List<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod(field.getName(), metadata);
            if (identifiableObjects == null || identifiableObjects.isEmpty()) {
                continue;
            }
            Grid grid = new ListGrid();
            grid.setTitle(identifiableObjects.get(0).getClass().getSimpleName() + "s");
            boolean nameable = false;
            grid.addHeader(new GridHeader("UID", false, false));
            grid.addHeader(new GridHeader("Name", false, false));
            if (NameableObject.class.isAssignableFrom(identifiableObjects.get(0).getClass())) {
                grid.addHeader(new GridHeader("ShortName", false, false));
                nameable = true;
            }
            grid.addHeader(new GridHeader("Code", false, false));
            for (IdentifiableObject identifiableObject : identifiableObjects) {
                grid.addRow();
                grid.addValue(identifiableObject.getUid());
                grid.addValue(identifiableObject.getName());
                if (nameable) {
                    grid.addValue(((NameableObject) identifiableObject).getShortName());
                }
                grid.addValue(identifiableObject.getCode());
            }
            grids.add(grid);
        }
    } else {
        IdentifiableObject identifiableObject = (IdentifiableObject) object;
        Grid grid = new ListGrid();
        grid.setTitle(identifiableObject.getClass().getSimpleName());
        grid.addEmptyHeaders(2);
        grid.addRow().addValue("UID").addValue(identifiableObject.getUid());
        grid.addRow().addValue("Name").addValue(identifiableObject.getName());
        if (NameableObject.class.isAssignableFrom(identifiableObject.getClass())) {
            grid.addRow().addValue("ShortName").addValue(((NameableObject) identifiableObject).getShortName());
            grid.addRow().addValue("Description").addValue(((NameableObject) identifiableObject).getDescription());
        }
        grid.addRow().addValue("Code").addValue(identifiableObject.getCode());
        grids.add(grid);
    }
    renderGrids(grids, response);
}
Also used : Field(java.lang.reflect.Field) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) NameableObject(org.hisp.dhis.common.NameableObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) GridHeader(org.hisp.dhis.common.GridHeader)

Example 99 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class DeletedObjectPostDeleteEventListener method onPostDelete.

@Override
public void onPostDelete(PostDeleteEvent event) {
    if (MetadataObject.class.isInstance(event.getEntity())) {
        IdentifiableObject identifiableObject = (IdentifiableObject) event.getEntity();
        DeletedObject deletedObject = new DeletedObject(identifiableObject);
        deletedObject.setDeletedBy(getUsername());
        event.getSession().persist(deletedObject);
    }
}
Also used : DeletedObject(org.hisp.dhis.deletedobject.DeletedObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 100 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class DefaultCollectionService method clearCollectionItems.

@Override
@SuppressWarnings("unchecked")
public void clearCollectionItems(IdentifiableObject object, String pvProperty) throws WebMessageException, InvocationTargetException, IllegalAccessException {
    Schema schema = schemaService.getDynamicSchema(object.getClass());
    if (!schema.haveProperty(pvProperty)) {
        throw new WebMessageException(WebMessageUtils.notFound("Property " + pvProperty + " does not exist on " + object.getClass().getName()));
    }
    Property property = schema.getProperty(pvProperty);
    if (!property.isCollection() || !property.isIdentifiableObject()) {
        throw new WebMessageException(WebMessageUtils.conflict("Only identifiable collections are allowed to be cleared."));
    }
    Collection<IdentifiableObject> collection = (Collection<IdentifiableObject>) property.getGetterMethod().invoke(object);
    manager.refresh(object);
    if (property.isOwner()) {
        collection.clear();
        manager.update(object);
    } else {
        for (IdentifiableObject itemObject : collection) {
            Schema itemSchema = schemaService.getDynamicSchema(property.getItemKlass());
            Property itemProperty = itemSchema.propertyByRole(property.getOwningRole());
            Collection<IdentifiableObject> itemCollection = (Collection<IdentifiableObject>) itemProperty.getGetterMethod().invoke(itemObject);
            itemCollection.remove(object);
            manager.update(itemObject);
            manager.refresh(itemObject);
        }
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Schema(org.hisp.dhis.schema.Schema) Collection(java.util.Collection) Property(org.hisp.dhis.schema.Property) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)124 List (java.util.List)76 Test (org.junit.Test)67 DhisSpringTest (org.hisp.dhis.DhisSpringTest)64 ClassPathResource (org.springframework.core.io.ClassPathResource)54 DataElement (org.hisp.dhis.dataelement.DataElement)44 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)39 User (org.hisp.dhis.user.User)37 DataSet (org.hisp.dhis.dataset.DataSet)24 ArrayList (java.util.ArrayList)22 ObjectReport (org.hisp.dhis.feedback.ObjectReport)22 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Schema (org.hisp.dhis.schema.Schema)19 HashMap (java.util.HashMap)18 TypeReport (org.hisp.dhis.feedback.TypeReport)18 Set (java.util.Set)15 ErrorReport (org.hisp.dhis.feedback.ErrorReport)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)15 Map (java.util.Map)14 Property (org.hisp.dhis.schema.Property)13