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;
}
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);
}
}
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);
}
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);
}
}
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);
}
}
}
Aggregations