use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getObjectProperty.
@GetMapping("/{uid}/{property}")
@ResponseBody
public RootNode getObjectProperty(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @RequestParam Map<String, String> rpParameters, TranslateParams translateParams, @CurrentUser User currentUser, HttpServletResponse response) throws Exception {
if (!"translations".equals(pvProperty)) {
setUserContext(currentUser, translateParams);
} else {
setUserContext(null, new TranslateParams(false));
}
try {
if (!aclService.canRead(currentUser, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.add(":all");
}
String fieldFilter = "[" + Joiner.on(',').join(fields) + "]";
cachePrivate(response);
return getObjectInternal(pvUid, rpParameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + fieldFilter), currentUser);
} finally {
UserContext.reset();
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getObjectInternal.
@SuppressWarnings("unchecked")
private RootNode getObjectInternal(String uid, Map<String, String> parameters, List<String> filters, List<String> fields, User currentUser) throws Exception {
WebOptions options = new WebOptions(parameters);
List<T> entities = getEntity(uid, options);
if (entities.isEmpty()) {
throw new WebMessageException(notFound(getEntityClass(), uid));
}
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, new ArrayList<>(), getPaginationData(options), options.getRootJunction());
query.setUser(currentUser);
query.setObjects(entities);
query.setDefaults(Defaults.valueOf(options.get("defaults", DEFAULTS)));
entities = (List<T>) queryService.query(query);
handleLinksAndAccess(entities, fields, true);
handleAttributeValues(entities, fields);
for (T entity : entities) {
postProcessResponseEntity(entity, options, parameters);
}
CollectionNode collectionNode = fieldFilterService.toCollectionNode(getEntityClass(), new FieldFilterParams(entities, fields, Defaults.valueOf(options.get("defaults", DEFAULTS))).setUser(currentUser));
if (options.isTrue("useWrapper") || entities.size() > 1) {
RootNode rootNode = NodeUtils.createMetadata(collectionNode);
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
} else {
List<Node> children = collectionNode.getChildren();
RootNode rootNode;
if (!children.isEmpty()) {
rootNode = NodeUtils.createRootNode(children.get(0));
} else {
rootNode = NodeUtils.createRootNode(new ComplexNode(getSchema().getSingular()));
}
rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(parameters.get("inclusionStrategy")));
return rootNode;
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class AbstractCrudController method deleteObject.
// --------------------------------------------------------------------------
// DELETE
// --------------------------------------------------------------------------
@DeleteMapping(value = "/{uid}")
@ResponseBody
public WebMessage deleteObject(@PathVariable("uid") String pvUid, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
if (!aclService.canDelete(currentUser, objects.get(0))) {
throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
}
preDeleteEntity(objects.get(0));
MetadataImportParams params = new MetadataImportParams().setImportReportMode(ImportReportMode.FULL).setUser(currentUser).setImportStrategy(ImportStrategy.DELETE).addObject(objects.get(0));
ImportReport importReport = importService.importMetadata(params);
postDeleteEntity(pvUid);
return objectReport(importReport);
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class AbstractCrudController method patchObject.
// --------------------------------------------------------------------------
// PATCH
// --------------------------------------------------------------------------
/**
* Adds support for HTTP Patch using JSON Patch (RFC 6902), updated object
* is run through normal metadata importer and internally looks like a
* normal PUT (after the JSON Patch has been applied).
*
* For now we only support the official mimetype
* "application/json-patch+json" but in future releases we might also want
* to support "application/json" after the old patch behavior has been
* removed.
*/
@ResponseBody
@PatchMapping(path = "/{uid}", consumes = "application/json-patch+json")
public WebMessage patchObject(@PathVariable("uid") String pvUid, @RequestParam Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
WebOptions options = new WebOptions(rpParameters);
List<T> entities = getEntity(pvUid, options);
if (entities.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
final T persistedObject = entities.get(0);
if (!aclService.canUpdate(currentUser, persistedObject)) {
throw new UpdateAccessDeniedException("You don't have the proper permissions to update this object.");
}
manager.resetNonOwnerProperties(persistedObject);
prePatchEntity(persistedObject);
final JsonPatch patch = jsonMapper.readValue(request.getInputStream(), JsonPatch.class);
final T patchedObject = jsonPatchManager.apply(patch, persistedObject);
// we don't allow changing IDs
((BaseIdentifiableObject) patchedObject).setId(persistedObject.getId());
// we don't allow changing UIDs
((BaseIdentifiableObject) patchedObject).setUid(persistedObject.getUid());
// Only supports new Sharing format
((BaseIdentifiableObject) patchedObject).clearLegacySharingCollections();
prePatchEntity(persistedObject, patchedObject);
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
if (!parameterValuesMap.containsKey("importReportMode")) {
parameterValuesMap.put("importReportMode", Collections.singletonList("ERRORS_NOT_OWNER"));
}
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUser).setImportStrategy(ImportStrategy.UPDATE).addObject(patchedObject);
ImportReport importReport = importService.importMetadata(params);
WebMessage webMessage = objectReport(importReport);
if (importReport.getStatus() == Status.OK) {
T entity = manager.get(getEntityClass(), pvUid);
postPatchEntity(entity);
} else {
webMessage.setStatus(Status.ERROR);
}
return webMessage;
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.UID in project dhis2-core by dhis2.
the class OrganisationUnitSupplierTest method verifyCodeSchemaForOu.
@Test
void verifyCodeSchemaForOu() throws SQLException {
// mock resultset data
when(mockResultSet.getLong("organisationunitid")).thenReturn(100L);
when(mockResultSet.getString("uid")).thenReturn("abcded");
when(mockResultSet.getString("code")).thenReturn("CODE1");
when(mockResultSet.getString("path")).thenReturn("/abcded");
when(mockResultSet.getInt("hierarchylevel")).thenReturn(1);
// create event to import
Event event = new Event();
event.setUid(CodeGenerator.generateUid());
event.setOrgUnit("CODE1");
// mock resultset extraction
mockResultSetExtractor(mockResultSet);
ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
importOptions.setOrgUnitIdScheme(IdScheme.CODE.name());
Map<String, OrganisationUnit> map = subject.get(importOptions, Collections.singletonList(event));
OrganisationUnit organisationUnit = map.get(event.getUid());
assertThat(organisationUnit, is(notNullValue()));
assertThat(organisationUnit.getId(), is(100L));
assertThat(organisationUnit.getUid(), is("abcded"));
assertThat(organisationUnit.getCode(), is("CODE1"));
assertThat(organisationUnit.getPath(), is("/abcded"));
assertThat(organisationUnit.getHierarchyLevel(), is(1));
}
Aggregations