use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", value = MULTIPLE_SAVE_RESOURCE_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveCompleteDataSetRegistration(@RequestBody CompleteDataSetRegistrationRequests completeDataSetRegistrationRequests, HttpServletResponse response) throws WebMessageException {
List<CompleteDataSetRegistration> registrations = new ArrayList<>();
for (CompleteDataSetRegistrationRequest completeDataSetRegistrationRequest : completeDataSetRegistrationRequests) {
String ds = completeDataSetRegistrationRequest.getDs();
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
}
String pe = completeDataSetRegistrationRequest.getPe();
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
String ou = completeDataSetRegistrationRequest.getOu();
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
String cc = completeDataSetRegistrationRequest.getCc();
String cp = completeDataSetRegistrationRequest.getCp();
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
// ---------------------------------------------------------------------
// Check locked status
// ---------------------------------------------------------------------
boolean multiOu = completeDataSetRegistrationRequest.isMultiOu();
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
}
// ---------------------------------------------------------------------
// Register as completed data set
// ---------------------------------------------------------------------
String sb = completeDataSetRegistrationRequest.getSb();
String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
Date cd = completeDataSetRegistrationRequest.getCd();
Date completionDate = (cd == null) ? new Date() : cd;
Set<OrganisationUnit> orgUnits = new HashSet<>();
orgUnits.add(organisationUnit);
if (multiOu) {
orgUnits.addAll(organisationUnit.getChildren());
}
addRegistrationsForOrgUnits(registrations, orgUnits, dataSet, period, attributeOptionCombo, storedBy, completionDate);
}
registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
use of org.hisp.dhis.webapi.mvc.annotation.ApiVersion in project dhis2-core by dhis2.
the class CustomRequestMappingHandlerMapping method getMappingForMethod.
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo info = super.getMappingForMethod(method, handlerType);
if (info == null) {
return null;
}
ApiVersion typeApiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
ApiVersion methodApiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class);
if (typeApiVersion == null && methodApiVersion == null) {
return info;
}
RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
if (methodsCondition.getMethods().isEmpty()) {
methodsCondition = new RequestMethodsRequestCondition(RequestMethod.GET);
}
Set<String> rqmPatterns = info.getPatternsCondition().getPatterns();
Set<String> patterns = new HashSet<>();
Set<DhisApiVersion> versions = getVersions(typeApiVersion, methodApiVersion);
for (String pattern : rqmPatterns) {
versions.stream().filter(version -> !version.isIgnore()).forEach(version -> {
if (!pattern.startsWith(version.getVersionString())) {
if (pattern.startsWith("/")) {
patterns.add("/" + version.getVersion() + pattern);
} else {
patterns.add("/" + version.getVersion() + "/" + pattern);
}
} else {
patterns.add(pattern);
}
});
}
PatternsRequestCondition patternsRequestCondition = new PatternsRequestCondition(patterns.toArray(new String[] {}), null, null, true, true, null);
return new RequestMappingInfo(null, patternsRequestCondition, methodsCondition, info.getParamsCondition(), info.getHeadersCondition(), info.getConsumesCondition(), info.getProducesCondition(), info.getCustomCondition());
}
Aggregations