Search in sources :

Example 41 with ObjectReport

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;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 42 with ObjectReport

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;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 43 with ObjectReport

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;
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 44 with ObjectReport

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;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 45 with 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;
}
Also used : CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) CreateAccessDeniedException(org.hisp.dhis.hibernate.exception.CreateAccessDeniedException) ApiToken(org.hisp.dhis.security.apikey.ApiToken) ObjectReport(org.hisp.dhis.feedback.ObjectReport) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ObjectReport (org.hisp.dhis.feedback.ObjectReport)46 TypeReport (org.hisp.dhis.feedback.TypeReport)29 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 ErrorReport (org.hisp.dhis.feedback.ErrorReport)22 ArrayList (java.util.ArrayList)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)13 User (org.hisp.dhis.user.User)9 Schema (org.hisp.dhis.schema.Schema)7 List (java.util.List)6 AttributeValue (org.hisp.dhis.attribute.AttributeValue)6 Test (org.junit.jupiter.api.Test)6 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 SchemaService (org.hisp.dhis.schema.SchemaService)5 Service (org.springframework.stereotype.Service)5 HashMap (java.util.HashMap)4 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)4 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)4 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3