Search in sources :

Example 31 with UPDATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UPDATED in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testUpdateDataSetWithSectionsAndGreyedFields.

@Test
void testUpdateDataSetWithSectionsAndGreyedFields() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    dbmsManager.clearSession();
    Section section1 = manager.get(Section.class, "JwcV2ZifEQf");
    assertNotNull(section1.getDataSet());
    assertEquals(1, section1.getCategoryCombos().size());
    assertTrue(section1.getGreyedFields().isEmpty());
    assertEquals(1, section1.getDataElements().size());
    assertNotNull(section1.getDataSet());
    Section section2 = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section2.getDataSet());
    assertEquals(1, section2.getCategoryCombos().size());
    assertEquals(1, section2.getGreyedFields().size());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section2.getDataSet());
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf_update.json").getInputStream(), RenderFormat.JSON);
    params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    bundle = objectBundleService.create(params);
    validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    manager.flush();
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    List<Section> sections = manager.getAll(Section.class);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, dataSets.size());
    assertEquals(2, sections.size());
    assertEquals(1, dataElementOperands.size());
    DataSet dataSet = dataSets.get(0);
    assertEquals("Updated Data Set", dataSet.getName());
    assertEquals(2, dataSet.getSections().size());
    assertNotNull(dataSet.getCreatedBy());
    section1 = manager.get(Section.class, "JwcV2ZifEQf");
    assertNotNull(section1.getDataSet());
    assertEquals(1, section1.getCategoryCombos().size());
    assertEquals(1, section1.getGreyedFields().size());
    assertEquals(1, section1.getDataElements().size());
    assertNotNull(section1.getDataSet());
    section2 = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section2.getDataSet());
    assertEquals(1, section2.getCategoryCombos().size());
    assertTrue(section2.getGreyedFields().isEmpty());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section2.getDataSet());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) Section(org.hisp.dhis.dataset.Section) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) List(java.util.List) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 32 with UPDATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UPDATED in project dhis2-core by dhis2.

the class MetadataImportServiceTest method testUpdateWithSkipTranslationIsTrue.

/**
 * 1. Create object with 2 translations 2. Update object with empty
 * translations and skipTranslation = true Expected: updated object still
 * has 2 translations
 */
@Test
void testUpdateWithSkipTranslationIsTrue() throws IOException {
    User user = createUser("A", "ALL");
    manager.save(user);
    injectSecurityContext(user);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_skipSharing.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    params.setSkipTranslation(false);
    params.setUser(user);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    DataSet dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
    assertNotNull(dataSet.getSharing().getUserGroups());
    assertEquals(2, dataSet.getTranslations().size());
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_update_skipSharing.json").getInputStream(), RenderFormat.JSON);
    params = createParams(ImportStrategy.UPDATE, metadata);
    params.setSkipTranslation(true);
    params.setUser(user);
    report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
    assertNotNull(dataSet.getSharing().getUserGroups());
    assertEquals(2, dataSet.getTranslations().size());
}
Also used : User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)9 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)8 User (org.hisp.dhis.user.User)8 Test (org.junit.jupiter.api.Test)8 Date (java.util.Date)7 List (java.util.List)7 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)6 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)6 DataSet (org.hisp.dhis.dataset.DataSet)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Event (org.hisp.dhis.dxf2.events.event.Event)5 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 Events (org.hisp.dhis.dxf2.events.event.Events)3 TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)3 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3