Search in sources :

Example 1 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class MessageConversationController method postObject.

private void postObject(HttpServletResponse response, HttpServletRequest request, MessageConversation messageConversation) throws WebMessageException {
    List<User> users = new ArrayList<>(messageConversation.getUsers());
    messageConversation.getUsers().clear();
    for (OrganisationUnit ou : messageConversation.getOrganisationUnits()) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou.getUid());
        if (organisationUnit == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Organisation Unit does not exist: " + ou.getUid()));
        }
        messageConversation.getUsers().addAll(organisationUnit.getUsers());
    }
    for (User u : users) {
        User user = userService.getUser(u.getUid());
        if (user == null) {
            throw new WebMessageException(WebMessageUtils.conflict("User does not exist: " + u.getUid()));
        }
        messageConversation.getUsers().add(user);
    }
    for (UserGroup ug : messageConversation.getUserGroups()) {
        UserGroup userGroup = userGroupService.getUserGroup(ug.getUid());
        if (userGroup == null) {
            throw new WebMessageException(WebMessageUtils.notFound("User Group does not exist: " + ug.getUid()));
        }
        messageConversation.getUsers().addAll(userGroup.getMembers());
    }
    if (messageConversation.getUsers().isEmpty()) {
        throw new WebMessageException(WebMessageUtils.conflict("No recipients selected."));
    }
    String metaData = MessageService.META_USER_AGENT + request.getHeader(ContextUtils.HEADER_USER_AGENT);
    int id = messageService.sendPrivateMessage(messageConversation.getSubject(), messageConversation.getText(), metaData, messageConversation.getUsers());
    org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation(id);
    response.addHeader("Location", MessageConversationSchemaDescriptor.API_ENDPOINT + "/" + conversation.getUid());
    webMessageService.send(WebMessageUtils.created("Message conversation created"), response, request);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) UserGroup(org.hisp.dhis.user.UserGroup)

Example 2 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class InterpretationController method postComment.

// -------------------------------------------------------------------------
// Comment
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/comments", method = RequestMethod.POST, consumes = { "text/html", "text/plain" })
public void postComment(@PathVariable("uid") String uid, @RequestBody String text, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Interpretation does not exist: " + uid));
    }
    InterpretationComment comment = interpretationService.addInterpretationComment(uid, text);
    String builder = InterpretationSchemaDescriptor.API_ENDPOINT + "/" + uid + "/comments/" + comment.getUid();
    response.addHeader("Location", builder);
    webMessageService.send(WebMessageUtils.created("Commented created"), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class AnalyticsUtils method getDataValueSetFromGrid.

/**
     * Generates a data value set based on the given grid with aggregated data.
     * Sets the created and last updated fields to the current date.
     * 
     * @param params the data query parameters.
     * @param grid the grid.
     * @return a data value set.
     */
public static DataValueSet getDataValueSetFromGrid(DataQueryParams params, Grid grid) {
    int dxInx = grid.getIndexOfHeader(DATA_X_DIM_ID);
    int peInx = grid.getIndexOfHeader(PERIOD_DIM_ID);
    int ouInx = grid.getIndexOfHeader(ORGUNIT_DIM_ID);
    int coInx = grid.getIndexOfHeader(CATEGORYOPTIONCOMBO_DIM_ID);
    int aoInx = grid.getIndexOfHeader(ATTRIBUTEOPTIONCOMBO_DIM_ID);
    int vlInx = grid.getWidth() - 1;
    Assert.isTrue(dxInx >= 0, "Data dimension index must be greater than or equal to zero");
    Assert.isTrue(peInx >= 0, "Period dimension index must be greater than or equal to zero");
    Assert.isTrue(ouInx >= 0, "Org unit dimension index must be greater than or equal to zero");
    Assert.isTrue(coInx >= 0, "Category option combo dimension index must be greater than or equal to zero");
    Assert.isTrue(aoInx >= 0, "Attribute option combo dimension index must be greater than or equal to zero");
    Assert.isTrue(vlInx >= 0, "Value index must be greater than or equal to zero");
    String created = DateUtils.getMediumDateString();
    DataValueSet dvs = new DataValueSet();
    Set<String> primaryKeys = Sets.newHashSet();
    for (List<Object> row : grid.getRows()) {
        DataValue dv = new DataValue();
        Object coc = row.get(coInx);
        Object aoc = row.get(aoInx);
        dv.setDataElement(String.valueOf(row.get(dxInx)));
        dv.setPeriod(String.valueOf(row.get(peInx)));
        dv.setOrgUnit(String.valueOf(row.get(ouInx)));
        dv.setCategoryOptionCombo(coc != null ? String.valueOf(coc) : null);
        dv.setAttributeOptionCombo(aoc != null ? String.valueOf(aoc) : null);
        dv.setValue(String.valueOf(row.get(vlInx)));
        dv.setComment(KEY_AGG_VALUE);
        dv.setStoredBy(KEY_AGG_VALUE);
        dv.setCreated(created);
        dv.setLastUpdated(created);
        if (!params.isDuplicatesOnly() || !primaryKeys.add(dv.getPrimaryKey())) {
            dvs.getDataValues().add(dv);
        }
    }
    return dvs;
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString)

Example 4 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class UserKeyJsonValueController method addUserKeyJsonValue.

/**
     * Creates a new KeyJsonValue Object on the current user with the key, namespace and value supplied.
     */
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public void addUserKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String body, @RequestParam(defaultValue = "false") boolean encrypt, HttpServletResponse response) throws IOException, WebMessageException {
    if (userKeyJsonValueService.getUserKeyJsonValue(currentUserService.getCurrentUser(), namespace, key) != null) {
        throw new WebMessageException(WebMessageUtils.conflict("The key '" + key + "' already exists in the namespace '" + namespace + "'."));
    }
    if (!renderService.isValidJson(body)) {
        throw new WebMessageException(WebMessageUtils.badRequest("The data is not valid JSON."));
    }
    UserKeyJsonValue userKeyJsonValue = new UserKeyJsonValue();
    userKeyJsonValue.setKey(key);
    userKeyJsonValue.setUser(currentUserService.getCurrentUser());
    userKeyJsonValue.setNamespace(namespace);
    userKeyJsonValue.setValue(body);
    userKeyJsonValue.setEncrypted(encrypt);
    userKeyJsonValueService.addUserKeyJsonValue(userKeyJsonValue);
    response.setStatus(HttpServletResponse.SC_CREATED);
    messageService.sendJson(WebMessageUtils.created("Key '" + key + "' in namespace '" + namespace + "' created."), response);
}
Also used : UserKeyJsonValue(org.hisp.dhis.userkeyjsonvalue.UserKeyJsonValue) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class AnalyticsUtils method getDataValueSetFromGrid.

/**
 * Generates a data value set based on the given grid with aggregated data.
 * Sets the created and last updated fields to the current date.
 *
 * @param params the data query parameters.
 * @param grid the grid.
 * @return a data value set.
 */
public static DataValueSet getDataValueSetFromGrid(DataQueryParams params, Grid grid) {
    int dxInx = grid.getIndexOfHeader(DATA_X_DIM_ID);
    int peInx = grid.getIndexOfHeader(PERIOD_DIM_ID);
    int ouInx = grid.getIndexOfHeader(ORGUNIT_DIM_ID);
    int coInx = grid.getIndexOfHeader(CATEGORYOPTIONCOMBO_DIM_ID);
    int aoInx = grid.getIndexOfHeader(ATTRIBUTEOPTIONCOMBO_DIM_ID);
    int vlInx = grid.getHeaderWidth() - 1;
    Assert.isTrue(dxInx >= 0, "Data dimension index must be greater than or equal to zero");
    Assert.isTrue(peInx >= 0, "Period dimension index must be greater than or equal to zero");
    Assert.isTrue(ouInx >= 0, "Org unit dimension index must be greater than or equal to zero");
    Assert.isTrue(coInx >= 0, "Category option combo dimension index must be greater than or equal to zero");
    Assert.isTrue(aoInx >= 0, "Attribute option combo dimension index must be greater than or equal to zero");
    Assert.isTrue(vlInx >= 0, "Value index must be greater than or equal to zero");
    String created = DateUtils.getMediumDateString();
    DataValueSet dvs = new DataValueSet();
    Set<String> primaryKeys = Sets.newHashSet();
    for (List<Object> row : grid.getRows()) {
        DataValue dv = new DataValue();
        Object coc = row.get(coInx);
        Object aoc = row.get(aoInx);
        dv.setDataElement(String.valueOf(row.get(dxInx)));
        dv.setPeriod(String.valueOf(row.get(peInx)));
        dv.setOrgUnit(String.valueOf(row.get(ouInx)));
        dv.setCategoryOptionCombo(coc != null ? String.valueOf(coc) : null);
        dv.setAttributeOptionCombo(aoc != null ? String.valueOf(aoc) : null);
        dv.setValue(String.valueOf(row.get(vlInx)));
        dv.setComment(KEY_AGG_VALUE);
        dv.setStoredBy(KEY_AGG_VALUE);
        dv.setCreated(created);
        dv.setLastUpdated(created);
        if (!params.isDuplicatesOnly() || !primaryKeys.add(dv.getPrimaryKey())) {
            dvs.getDataValues().add(dv);
        }
    }
    return dvs;
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DimensionalObject(org.hisp.dhis.common.DimensionalObject) DataDimensionalItemObject(org.hisp.dhis.common.DataDimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 Test (org.junit.jupiter.api.Test)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ArrayList (java.util.ArrayList)8 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 Date (java.util.Date)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)6 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)6 HttpUtils (org.hisp.dhis.system.util.HttpUtils)6 User (org.hisp.dhis.user.User)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 List (java.util.List)5 Map (java.util.Map)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)4 Event (org.hisp.dhis.dxf2.events.event.Event)4 HashMap (java.util.HashMap)3