use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithServerError.
@Test
void testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithServerError() {
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
HttpResponse httpResponse = mock(HttpResponse.class);
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.GATEWAY_TIMEOUT.value());
when(metadataSystemSettingService.getVersionDetailsUrl("testVersion")).thenReturn(versionUrl);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
mocked.when(() -> HttpUtils.httpGET(versionUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
assertThrows(MetadataVersionServiceException.class, () -> target.getRemoteMetadataVersion("testVersion"), "Server Error. Http call failed with status code: " + HttpStatus.GATEWAY_TIMEOUT.value() + " Caused by: " + response);
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class MetadataVersionDelegateTest method testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithClientError.
@Test
void testShouldThrowExceptionWhenGettingRemoteMetadataVersionWithClientError() {
when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
HttpResponse httpResponse = mock(HttpResponse.class);
DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.CONFLICT.value());
when(metadataSystemSettingService.getVersionDetailsUrl("testVersion")).thenReturn(versionUrl);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
mocked.when(() -> HttpUtils.httpGET(versionUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
assertThrows(MetadataVersionServiceException.class, () -> target.getRemoteMetadataVersion("testVersion"), "Client Error. Http call failed with status code: " + HttpStatus.CONFLICT.value() + " Caused by: " + response);
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class AppController method installApp.
@PostMapping
@PreAuthorize("hasRole('ALL') or hasRole('M_dhis-web-app-management')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void installApp(@RequestParam("file") MultipartFile file) throws IOException, WebMessageException {
File tempFile = File.createTempFile("IMPORT_", "_ZIP");
file.transferTo(tempFile);
AppStatus status = appManager.installApp(tempFile, file.getOriginalFilename());
if (!status.ok()) {
String message = i18nManager.getI18n().getString(status.getMessage());
throw new WebMessageException(conflict(message));
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class AuditController method getFileAudit.
/**
* Returns the file with the given uid
*
* @param uid the unique id of the file resource
*/
@GetMapping("/files/{uid}")
public void getFileAudit(@PathVariable String uid, HttpServletResponse response) throws WebMessageException {
FileResource fileResource = fileResourceService.getFileResource(uid);
if (fileResource == null || fileResource.getDomain() != FileResourceDomain.DATA_VALUE) {
throw new WebMessageException(notFound("No file found with uid '" + uid + "'"));
}
FileResourceStorageStatus storageStatus = fileResource.getStorageStatus();
if (storageStatus != FileResourceStorageStatus.STORED) {
// HTTP 409, for lack of a more suitable status code
throw new WebMessageException(conflict("The content is being processed and is not available yet. Try again later.", "The content requested is in transit to the file store and will be available at a later time.").setResponse(new FileResourceWebMessageResponse(fileResource)));
}
response.setContentType(fileResource.getContentType());
response.setContentLength(Long.valueOf(fileResource.getContentLength()).intValue());
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileResource.getName());
try {
fileResourceService.copyFileResourceContent(fileResource, response.getOutputStream());
} catch (IOException e) {
throw new WebMessageException(error("Failed fetching the file from storage", "There was an exception when trying to fetch the file from the storage backend, could be network or filesystem related"));
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method deleteCompleteDataSetRegistration.
// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@DeleteMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteCompleteDataSetRegistration(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
Set<DataSet> dataSets = new HashSet<>(manager.getByUid(DataSet.class, ds));
if (dataSets.size() != ds.size()) {
throw new WebMessageException(conflict("Illegal data set identifier in this list: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(conflict("Illegal period identifier: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(conflict("Illegal organisation unit identifier: " + ou));
}
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
// ---------------------------------------------------------------------
// Check locked status
// ---------------------------------------------------------------------
User user = currentUserService.getCurrentUser();
List<String> lockedDataSets = new ArrayList<>();
for (DataSet dataSet : dataSets) {
if (!dataSetService.getLockStatus(user, dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu).isOpen()) {
lockedDataSets.add(dataSet.getUid());
}
}
if (lockedDataSets.size() != 0) {
throw new WebMessageException(conflict("Locked Data set(s) : " + StringUtils.join(lockedDataSets, ", ")));
}
// ---------------------------------------------------------------------
// Un-register as completed data set
// ---------------------------------------------------------------------
Set<OrganisationUnit> orgUnits = new HashSet<>();
orgUnits.add(organisationUnit);
if (multiOu) {
orgUnits.addAll(organisationUnit.getChildren());
}
unRegisterCompleteDataSet(dataSets, period, orgUnits, attributeOptionCombo);
}
Aggregations