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;
}
}
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());
}
}
}
Aggregations