Search in sources :

Example 36 with ID

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

the class RelationshipController method updateRelationshipJson.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@PutMapping(path = "/{id}", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage updateRelationshipJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    Relationship relationship = relationshipService.getRelationshipByUid(id);
    if (relationship == null) {
        return notFound("No relationship with id '" + id + "' was found.");
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = relationshipService.updateRelationshipJson(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    return importSummary(importSummary);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 37 with ID

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

the class TrackedEntityAttributeController method reserve.

// Helpers
private List<ReservedValue> reserve(String id, int numberToReserve, int daysToLive) throws WebMessageException {
    if (numberToReserve > 1000 || numberToReserve < 1) {
        throw new WebMessageException(badRequest("You can only reserve between 1 and 1000 values in a single request."));
    }
    Map<String, List<String>> params = context.getParameterValuesMap();
    TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(id);
    if (attribute == null) {
        throw new WebMessageException(notFound("No attribute found with id " + id));
    }
    if (attribute.getTextPattern() == null) {
        throw new WebMessageException(conflict("This attribute has no pattern"));
    }
    Map<String, String> values = getRequiredValues(attribute, params);
    Date expiration = DateUtils.getDateAfterAddition(new Date(), daysToLive);
    try {
        List<ReservedValue> result = reservedValueService.reserve(attribute, numberToReserve, values, expiration);
        if (result.isEmpty()) {
            throw new WebMessageException(conflict("Unable to reserve id. This may indicate that there are too few available ids left."));
        }
        return result;
    } catch (ReserveValueException ex) {
        throw new WebMessageException(conflict(ex.getMessage()));
    } catch (TextPatternGenerationException ex) {
        throw new WebMessageException(error(ex.getMessage()));
    }
}
Also used : ReservedValue(org.hisp.dhis.reservedvalue.ReservedValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TextPatternGenerationException(org.hisp.dhis.textpattern.TextPatternGenerationException) ReserveValueException(org.hisp.dhis.reservedvalue.ReserveValueException) List(java.util.List) Date(java.util.Date)

Example 38 with ID

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

the class TrackedEntityInstanceController method updateTrackedEntityInstanceXml.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@PutMapping(value = "/{id}", consumes = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage updateTrackedEntityInstanceXml(@PathVariable String id, @RequestParam(required = false) String program, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceXml(id, program, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    return importSummary(importSummary);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with ID

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

the class ProgramSupplierTest method verifySupplier.

@ParameterizedTest
@MethodSource("data")
public void verifySupplier(String idScheme) throws SQLException {
    when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(false);
    when(mockResultSet.getLong("id")).thenReturn(100L);
    when(mockResultSet.getString("uid")).thenReturn("abcded");
    when(mockResultSet.getString("code")).thenReturn("ALFA");
    when(mockResultSet.getString("name")).thenReturn("My Program");
    when(mockResultSet.getString("type")).thenReturn(ProgramType.WITHOUT_REGISTRATION.getValue());
    when(mockResultSet.getString("program_sharing")).thenReturn(generateSharing(null, "rw------", false));
    when(mockResultSet.getInt("opendaysaftercoenddate")).thenReturn(42);
    when(mockResultSet.getLong("catcombo_id")).thenReturn(200L);
    when(mockResultSet.getString("catcombo_uid")).thenReturn("389dh83");
    when(mockResultSet.getString("catcombo_code")).thenReturn("BETA");
    when(mockResultSet.getString("catcombo_name")).thenReturn("My CatCombo");
    when(mockResultSet.getLong("ps_id")).thenReturn(5L, 6L);
    when(mockResultSet.getString("ps_uid")).thenReturn("abcd5", "abcd6");
    when(mockResultSet.getString("ps_code")).thenReturn("cod5", "cod6");
    when(mockResultSet.getString("ps_name")).thenReturn("name5", "name6");
    when(mockResultSet.getInt("sort_order")).thenReturn(1, 2);
    when(mockResultSet.getString("ps_sharing")).thenReturn(generateSharing(null, "rw------", false));
    when(mockResultSet.getString("ps_feature_type")).thenReturn(null, "POINT");
    when(mockResultSet.getBoolean("ps_repeatable")).thenReturn(true, false);
    when(mockResultSet.getString("validationstrategy")).thenReturn("ON_COMPLETE");
    when(mockResultSet.getObject("uid")).thenReturn("abcded");
    when(mockResultSet.getObject("id")).thenReturn(100L);
    when(mockResultSet.getObject("name")).thenReturn("My Program");
    when(mockResultSet.getObject("code")).thenReturn("ALFA");
    // mock resultset extraction
    mockResultSetExtractorWithoutParameters(mockResultSet);
    ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
    importOptions.getIdSchemes().setProgramIdScheme(idScheme);
    final Map<String, Program> map = subject.get(importOptions, null);
    Program program = map.get(getIdByScheme(idScheme));
    assertThat(program, is(notNullValue()));
    assertThat(program.getProgramStages(), hasSize(2));
    assertThat(program.getId(), is(100L));
    assertThat(program.getCode(), is("ALFA"));
    assertThat(program.getName(), is("My Program"));
    assertThat(program.getProgramType(), is(ProgramType.WITHOUT_REGISTRATION));
    assertThat(program.getSharing().getPublicAccess(), is("rw------"));
    assertThat(program.getOpenDaysAfterCoEndDate(), is(42));
    assertThat(program.getCategoryCombo(), is(notNullValue()));
    assertThat(program.getCategoryCombo().getId(), is(200L));
    assertThat(program.getCategoryCombo().getUid(), is("389dh83"));
    assertThat(program.getCategoryCombo().getName(), is("My CatCombo"));
    assertThat(program.getCategoryCombo().getCode(), is("BETA"));
// TODO assert more data
}
Also used : Program(org.hisp.dhis.program.Program) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 40 with ID

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

the class DataValueSetImportValidatorTest method assertConflict.

private static void assertConflict(ErrorCode expectedError, String expectedValue, ImportContext context, String... expectedObjects) {
    ImportSummary summary = context.getSummary();
    assertEquals(1, summary.getConflictCount());
    ImportConflict conflict = summary.getConflicts().iterator().next();
    String object = conflict.getObject();
    assertEquals(expectedError, conflict.getErrorCode(), "unexpected conflict type: ");
    if (expectedObjects.length > 0) {
        assertEquals(expectedObjects[0], object, "unexpected object ID: ");
    }
    Map<String, String> objects = conflict.getObjects();
    assertEquals(expectedObjects.length, objects.size(), "unexpected number of object IDs: ");
    Iterator<String> actualObjectsIter = objects.values().iterator();
    for (int i = 0; i < expectedObjects.length; i++) {
        assertEquals(expectedObjects[i], actualObjectsIter.next(), "unexpected object ID for object " + i + ": ");
    }
    assertEquals(substituteObjectPlaceholders(expectedValue, conflict), conflict.getValue());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)41 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)39 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 InputStream (java.io.InputStream)24 User (org.hisp.dhis.user.User)21 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)18 IOException (java.io.IOException)17 Event (org.hisp.dhis.dxf2.events.event.Event)16 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)13 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 DataElement (org.hisp.dhis.dataelement.DataElement)10 Test (org.junit.jupiter.api.Test)10 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)9 Lists (com.google.common.collect.Lists)8 Collectors (java.util.stream.Collectors)8 HashMap (java.util.HashMap)7