use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class TranslateAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
className = className != null && CLASS_ALIAS.containsKey(className) ? CLASS_ALIAS.get(className) : className;
log.info("Classname: " + className + ", uid: " + uid + ", loc: " + loc);
IdentifiableObject object = identifiableObjectManager.getObject(uid, className);
HttpServletRequest request = ServletActionContext.getRequest();
Set<ObjectTranslation> listObjectTranslation = new HashSet<>(object.getTranslations());
for (TranslationProperty p : TranslationProperty.values()) {
Enumeration<String> paramNames = request.getParameterNames();
Collections.list(paramNames).forEach(paramName -> {
if (paramName.equalsIgnoreCase(p.getName())) {
String[] paramValues = request.getParameterValues(paramName);
if (!ArrayUtils.isEmpty(paramValues) && StringUtils.isNotEmpty(paramValues[0])) {
listObjectTranslation.removeIf(o -> o.getProperty().equals(p) && o.getLocale().equalsIgnoreCase(loc));
listObjectTranslation.add(new ObjectTranslation(loc, p, paramValues[0]));
}
}
});
}
identifiableObjectManager.updateTranslations(object, listObjectTranslation);
return SUCCESS;
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class AbstractWebApiTest method testGetAll.
@Test
public void testGetAll() throws Exception {
Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaultObjectMap = manager.getDefaults();
IdentifiableObject defaultTestObject = defaultObjectMap.get(testClass);
int valueToTest = defaultTestObject != null ? 5 : 4;
manager.save(createTestObject(testClass, 'A'));
manager.save(createTestObject(testClass, 'B'));
manager.save(createTestObject(testClass, 'C'));
manager.save(createTestObject(testClass, 'D'));
MockHttpSession session = getSession("ALL");
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll(ResponseDocumentation.pager());
fieldDescriptors.add(fieldWithPath(schema.getPlural()).description(schema.getPlural()));
mvc.perform(get(schema.getRelativeApiEndpoint()).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$." + schema.getPlural()).isArray()).andExpect(jsonPath("$." + schema.getPlural() + ".length()").value(valueToTest)).andDo(documentPrettyPrint(schema.getPlural() + "/all", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
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);
}
Aggregations