Search in sources :

Example 16 with DataAccessForm

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

the class DataAccessResource method getDataAccessForm.

@GET
@Path("/form")
@Timed
public Mica.DataAccessFormDto getDataAccessForm(@QueryParam("lang") String lang) {
    Optional<DataAccessForm> d = dataAccessFormService.find();
    if (!d.isPresent())
        throw NoSuchDataAccessFormException.withDefaultMessage();
    DataAccessForm dataAccessForm = d.get();
    Mica.DataAccessFormDto.Builder builder = Mica.DataAccessFormDto.newBuilder(dtos.asDto(dataAccessForm)).clearProperties().clearPdfTemplates();
    String langTag = !Strings.isNullOrEmpty(lang) ? Locale.forLanguageTag(lang).toLanguageTag() : LanguageTag.UNDETERMINED;
    Map<String, LocalizedString> properties = dataAccessForm.getProperties().entrySet().stream().map(e -> Maps.immutableEntry(e.getKey(), new LocalizedString().forLanguageTag(langTag, e.getValue().get(langTag)))).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
    builder.addAllProperties(dtos.asDtoList(properties));
    return builder.build();
}
Also used : DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) LocalizedString(org.obiba.mica.core.domain.LocalizedString) FileResource(org.obiba.mica.file.rest.FileResource) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Maps(com.google.common.collect.Maps) NoSuchDataAccessFormException(org.obiba.mica.micaConfig.NoSuchDataAccessFormException) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Timed(com.codahale.metrics.annotation.Timed) Strings(com.google.common.base.Strings) Component(org.springframework.stereotype.Component) QueryParam(javax.ws.rs.QueryParam) LanguageTag(sun.util.locale.LanguageTag) Collectors.toMap(java.util.stream.Collectors.toMap) DataAccessFormService(org.obiba.mica.micaConfig.service.DataAccessFormService) Locale(java.util.Locale) Map(java.util.Map) Mica(org.obiba.mica.web.model.Mica) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Dtos(org.obiba.mica.web.model.Dtos) LocalizedString(org.obiba.mica.core.domain.LocalizedString) LocalizedString(org.obiba.mica.core.domain.LocalizedString) DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 17 with DataAccessForm

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

the class DataAccessFormService method createDefaultDataAccessForm.

private DataAccessForm createDefaultDataAccessForm() {
    DataAccessForm form = new DataAccessForm();
    form.setDefinition(getDefaultDataAccessFormResourceAsString("definition.json"));
    form.setSchema(getDefaultDataAccessFormResourceAsString("schema.json"));
    form.setCsvExportFormat(getDefaultDataAccessFormResourceAsString("export-csv-schema.json"));
    form.setTitleFieldPath("projectTitle");
    form.setSummaryFieldPath("summary");
    return form;
}
Also used : DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm)

Aggregations

DataAccessForm (org.obiba.mica.micaConfig.domain.DataAccessForm)17 Locale (java.util.Locale)3 Timed (com.codahale.metrics.annotation.Timed)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)2 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Inject (javax.inject.Inject)1 QueryParam (javax.ws.rs.QueryParam)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 DateTime (org.joda.time.DateTime)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 IdentifierGenerator (org.obiba.mica.core.support.IdentifierGenerator)1 Attachment (org.obiba.mica.file.Attachment)1 FileResource (org.obiba.mica.file.rest.FileResource)1