use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class ObjectBundleReportTest method createTypeReport.
private TypeReport createTypeReport(Class<?> mainKlass, Class<?> errorKlass) {
ObjectReport objectReport0 = new ObjectReport(mainKlass, 0);
ObjectReport objectReport1 = new ObjectReport(mainKlass, 1);
ObjectReport objectReport2 = new ObjectReport(mainKlass, 2);
objectReport0.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
objectReport1.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
objectReport2.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
TypeReport typeReport = new TypeReport(mainKlass);
typeReport.addObjectReport(objectReport0);
typeReport.addObjectReport(objectReport1);
typeReport.addObjectReport(objectReport2);
return typeReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class DefaultMetadataWorkflowService method createImportReportWithError.
private ImportReport createImportReportWithError(MetadataProposal proposal, ErrorCode errorCode, String property, Object... args) {
Class<? extends IdentifiableObject> objType = proposal.getTarget().getType();
ImportReport importReport = new ImportReport();
importReport.setStatus(Status.ERROR);
ObjectReport objectReport = new ObjectReport(objType, null);
ErrorReport errorReport = new ErrorReport(MetadataProposal.class, errorCode, args);
errorReport.setErrorProperty(property);
errorReport.setErrorProperties(singletonList(property));
objectReport.addErrorReport(errorReport);
TypeReport typeReport = new TypeReport(objType);
typeReport.addObjectReport(objectReport);
importReport.addTypeReport(typeReport);
return importReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class BulkPatchValidatorService method createTypeReport.
private TypeReport createTypeReport(ErrorReport errorReport) {
ObjectReport objectReport = new ObjectReport(JsonPatchException.class, 0);
objectReport.addErrorReport(errorReport);
TypeReport typeReport = new TypeReport(JsonPatchException.class);
typeReport.addObjectReport(objectReport);
return typeReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class JobConfigurationController method executeJobConfiguration.
@PostMapping(value = "{uid}/execute", produces = { APPLICATION_JSON_VALUE, "application/javascript" })
public ObjectReport executeJobConfiguration(@PathVariable("uid") String uid) throws WebMessageException {
JobConfiguration jobConfiguration = jobConfigurationService.getJobConfigurationByUid(uid);
checkConfigurable(jobConfiguration, HttpStatus.FORBIDDEN, "Job %s is a system job that cannot be executed.");
ObjectReport objectReport = new ObjectReport(JobConfiguration.class, 0);
boolean success = schedulingManager.executeNow(jobConfiguration);
if (!success) {
objectReport.addErrorReport(new ErrorReport(JobConfiguration.class, new ErrorMessage(ErrorCode.E7006, jobConfiguration.getName())));
}
return objectReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class ApiTokenController method postJsonObject.
@PostMapping(consumes = "application/json")
@ResponseBody
public WebMessage postJsonObject(HttpServletRequest request) throws Exception {
final ApiToken apiToken = deserializeJsonEntity(request);
User user = currentUserService.getCurrentUser();
if (!aclService.canCreate(user, getEntityClass())) {
throw new CreateAccessDeniedException("You don't have the proper permissions to create this object.");
}
apiToken.getTranslations().clear();
// Validate input values is ok
validateBeforeCreate(apiToken);
// We only make personal access tokens for now
apiToken.setType(ApiTokenType.PERSONAL_ACCESS_TOKEN);
// Generate key and set default values
apiTokenService.initToken(apiToken);
// Save raw key to send in response
final String rawKey = apiToken.getKey();
// Hash the raw token key and overwrite value in the entity to persist
final String hashedKey = apiTokenService.hashKey(apiToken.getKey());
apiToken.setKey(hashedKey);
// Continue POST import as usual
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap()).setImportReportMode(ImportReportMode.FULL).setUser(user).setImportStrategy(ImportStrategy.CREATE).addObject(apiToken);
final ObjectReport objectReport = importService.importMetadata(params).getFirstObjectReport();
final String uid = objectReport.getUid();
WebMessage webMessage = objectReport(objectReport);
if (webMessage.getStatus() == Status.OK) {
webMessage.setHttpStatus(HttpStatus.CREATED);
webMessage.setLocation(getSchema().getRelativeApiEndpoint() + "/" + uid);
// Set our custom web response object that includes the new
// generated key.
webMessage.setResponse(new ApiTokenCreationResponse(objectReport, rawKey));
} else {
webMessage.setStatus(Status.ERROR);
}
return webMessage;
}
Aggregations