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