use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateAndUpdateMetadata1.
@Test
public void testCreateAndUpdateMetadata1() throws IOException {
defaultSetup();
Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
assertEquals(4, dataElementMap.size());
assertNotNull(userGroup);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_create_and_update1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
objectBundleService.commit(bundle);
DataElement dataElementA = dataElementMap.get("deabcdefghA");
DataElement dataElementB = dataElementMap.get("deabcdefghB");
DataElement dataElementC = dataElementMap.get("deabcdefghC");
DataElement dataElementD = dataElementMap.get("deabcdefghD");
assertNotNull(dataElementA);
assertNotNull(dataElementB);
assertNotNull(dataElementC);
assertNotNull(dataElementD);
assertEquals("DEA", dataElementA.getName());
assertEquals("DEB", dataElementB.getName());
assertEquals("DEC", dataElementC.getName());
assertEquals("DED", dataElementD.getName());
assertEquals("DECA", dataElementA.getCode());
assertEquals("DECB", dataElementB.getCode());
assertEquals("DECC", dataElementC.getCode());
assertEquals("DECD", dataElementD.getCode());
assertEquals("DESA", dataElementA.getShortName());
assertEquals("DESB", dataElementB.getShortName());
assertEquals("DESC", dataElementC.getShortName());
assertEquals("DESD", dataElementD.getShortName());
assertEquals("DEDA", dataElementA.getDescription());
assertEquals("DEDB", dataElementB.getDescription());
assertEquals("DEDC", dataElementC.getDescription());
assertEquals("DEDD", dataElementD.getDescription());
assertEquals(1, dataElementA.getUserGroupAccesses().size());
assertEquals(0, dataElementB.getUserGroupAccesses().size());
assertEquals(1, dataElementC.getUserGroupAccesses().size());
assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class HibernateGenericStore method save.
@Override
public void save(T object, User user, boolean clearSharing) {
String username = user != null ? user.getUsername() : "system-process";
if (IdentifiableObject.class.isAssignableFrom(object.getClass())) {
BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
identifiableObject.setAutoFields();
identifiableObject.setLastUpdatedBy(user);
if (clearSharing) {
identifiableObject.setPublicAccess(AccessStringHelper.DEFAULT);
if (identifiableObject.getUserGroupAccesses() != null) {
identifiableObject.getUserGroupAccesses().clear();
}
if (identifiableObject.getUserAccesses() != null) {
identifiableObject.getUserAccesses().clear();
}
}
if (identifiableObject.getUser() == null) {
identifiableObject.setUser(user);
}
}
if (user != null && aclService.isShareable(clazz)) {
BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
if (clearSharing) {
if (aclService.canMakePublic(user, identifiableObject.getClass())) {
if (aclService.defaultPublic(identifiableObject.getClass())) {
identifiableObject.setPublicAccess(AccessStringHelper.READ_WRITE);
}
} else if (aclService.canMakePrivate(user, identifiableObject.getClass())) {
identifiableObject.setPublicAccess(AccessStringHelper.newInstance().build());
}
}
if (!checkPublicAccess(user, identifiableObject)) {
AuditLogUtil.infoWrapper(log, username, object, AuditLogUtil.ACTION_CREATE_DENIED);
throw new CreateAccessDeniedException(object.toString());
}
}
AuditLogUtil.infoWrapper(log, username, object, AuditLogUtil.ACTION_CREATE);
getSession().save(object);
if (MetadataObject.class.isInstance(object)) {
deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery((IdentifiableObject) object));
}
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testAddDeleteCollectionItem.
@Test
public void testAddDeleteCollectionItem() throws Exception {
MockHttpSession session = getSession("ALL");
DataElementCategory category = createDataElementCategory('A');
manager.save(category);
Schema schema = schemaService.getSchema(DataElementCategory.class);
List<Property> properties = schema.getProperties();
for (Property property : properties) {
if (property.isCollection()) {
String collectionName = property.getCollectionName();
IdentifiableObject item = createTestObject(property.getItemKlass(), 'A', category);
if (item == null) {
continue;
} else {
manager.save(item);
}
mvc.perform(post("/" + ENDPOINT + "/" + category.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint(ENDPOINT + "/add" + collectionName)).andExpect(status().isNoContent());
mvc.perform(delete("/" + ENDPOINT + "/" + category.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint(ENDPOINT + "/delete" + collectionName)).andExpect(status().isNoContent());
}
}
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testAddDeleteCollectionItem.
@Test
public void testAddDeleteCollectionItem() throws Exception {
MockHttpSession session = getSession("ALL");
DataElement de = createDataElement('A');
manager.save(de);
Schema schema = schemaService.getSchema(DataElement.class);
List<Property> properties = schema.getProperties();
for (Property property : properties) {
if (property.isCollection()) {
String collectionName = property.getCollectionName();
IdentifiableObject item = createTestObject(property.getItemKlass(), 'A');
if (item == null) {
continue;
} else {
manager.save(item);
}
mvc.perform(post("/dataElements/" + de.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("data-elements/add" + collectionName)).andExpect(status().isNoContent());
mvc.perform(delete("/dataElements/" + de.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("data-elements/delete" + collectionName)).andExpect(status().isNoContent());
}
}
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class GetTranslationsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
className = className != null && CLASS_ALIAS.containsKey(className) ? CLASS_ALIAS.get(className) : className;
Locale locale = LocaleUtils.getLocale(loc);
IdentifiableObject object = identifiableObjectManager.getObject(objectUid, className);
translations = TranslationUtils.convertTranslations(object.getTranslations(), locale);
return SUCCESS;
}
Aggregations