Search in sources :

Example 1 with AbstractDataAccessEntityForm

use of org.obiba.mica.micaConfig.domain.AbstractDataAccessEntityForm in project mica2 by obiba.

the class DataAccessRequestUtilService method getRequestEndDate.

public Date getRequestEndDate(DataAccessEntity request) {
    AbstractDataAccessEntityForm dataAccessForm = getDataAccessForm(request);
    if (!dataAccessForm.hasEndDateFieldPath())
        return null;
    String value = getRequestField(request, dataAccessForm.getEndDateFieldPath());
    if (Strings.isNullOrEmpty(value))
        return null;
    try {
        return ISO_8601.parse(value);
    } catch (ParseException e) {
        log.warn("Not a valid (ISO 8601) date format: {}", value);
        return null;
    }
}
Also used : AbstractDataAccessEntityForm(org.obiba.mica.micaConfig.domain.AbstractDataAccessEntityForm) ParseException(java.text.ParseException)

Example 2 with AbstractDataAccessEntityForm

use of org.obiba.mica.micaConfig.domain.AbstractDataAccessEntityForm in project mica2 by obiba.

the class DataAccessRequestUtilService method setRequestTitle.

/**
 * This method merely assigns a value to a path where all parent nodes already exist.
 * <p>
 * TODO create a setRequestField() such that all non-existent nodes are created and proper type checking is made.
 *
 * @param request
 * @param title
 */
void setRequestTitle(DataAccessEntity request, String title) {
    AbstractDataAccessEntityForm dataAccessForm = getDataAccessForm(request);
    String titleFieldPath = dataAccessForm.getTitleFieldPath();
    if (!Strings.isNullOrEmpty(titleFieldPath)) {
        String rawContent = request.getContent();
        if (!Strings.isNullOrEmpty(titleFieldPath) && !Strings.isNullOrEmpty(rawContent)) {
            Object content = Configuration.defaultConfiguration().jsonProvider().parse(rawContent);
            DocumentContext context = JsonPath.using(conf).parse(content);
            try {
                context.read(titleFieldPath);
                context.set(titleFieldPath, title);
            } catch (PathNotFoundException ex) {
                context.put("$", titleFieldPath.replaceAll("^\\$\\.", ""), title);
            } catch (InvalidPathException e) {
                log.warn("Invalid jsonpath {}", titleFieldPath);
            }
            request.setContent(context.jsonString());
        }
    }
}
Also used : AbstractDataAccessEntityForm(org.obiba.mica.micaConfig.domain.AbstractDataAccessEntityForm)

Aggregations

AbstractDataAccessEntityForm (org.obiba.mica.micaConfig.domain.AbstractDataAccessEntityForm)2 ParseException (java.text.ParseException)1