Search in sources :

Example 1 with LocalizedString

use of org.obiba.mica.core.domain.LocalizedString in project mica2 by obiba.

the class DceIdAggregationMetaDataHelper method mapIdToMetadata.

private void mapIdToMetadata(Map<String, AggregationMetaDataProvider.LocalizedMetaData> map, BaseStudy study, Population population, DataCollectionEvent dce) {
    MonikerData md = new MonikerData(study.getAcronym(), population, dce);
    LocalizedString title = new LocalizedString();
    study.getAcronym().entrySet().forEach(e -> title.put(e.getKey(), md.getTitle(e.getKey())));
    LocalizedString description = new LocalizedString();
    study.getAcronym().entrySet().forEach(e -> description.put(e.getKey(), md.getDescription(e.getKey())));
    if (dce == null) {
        map.put(StudyTable.getDataCollectionEventUId(study.getId(), population.getId()), new AggregationMetaDataProvider.LocalizedMetaData(title, description, "", null, null));
    } else {
        String start = dce.hasStart() ? dce.getStart().getYearMonth() : null;
        String end = dce.hasEnd() ? dce.getEnd().getYearMonth() : null;
        map.put(StudyTable.getDataCollectionEventUId(study.getId(), population.getId(), dce.getId()), new AggregationMetaDataProvider.LocalizedMetaData(title, description, dce.getClass().getSimpleName(), start, end));
    }
}
Also used : LocalizedString(org.obiba.mica.core.domain.LocalizedString) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 2 with LocalizedString

use of org.obiba.mica.core.domain.LocalizedString in project mica2 by obiba.

the class DatasetService method getNextId.

@Nullable
protected String getNextId(@Nullable LocalizedString suggested) {
    if (suggested == null)
        return null;
    String prefix = suggested.asUrlSafeString().toLowerCase();
    if (Strings.isNullOrEmpty(prefix))
        return null;
    String next = prefix;
    try {
        findById(next);
        for (int i = 1; i <= 1000; i++) {
            next = prefix + "-" + i;
            findById(next);
        }
        return null;
    } catch (NoSuchDatasetException e) {
        return next;
    }
}
Also used : NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Nullable(javax.annotation.Nullable)

Example 3 with LocalizedString

use of org.obiba.mica.core.domain.LocalizedString in project mica2 by obiba.

the class CustomTranslationsResource method importTranslations.

@PUT
@Path("/import")
@Consumes("application/json")
public Response importTranslations(String translations, @QueryParam("merge") @DefaultValue("false") boolean merge) throws IOException {
    MicaConfig config = micaConfigService.getConfig();
    JsonNode node = objectMapper.readTree(translations);
    List<String> locales = config.getLocalesAsString();
    if (!config.hasTranslations()) {
        config.setTranslations(new LocalizedString());
    }
    if (merge) {
        locales.forEach(l -> {
            JsonNode merged = micaConfigService.mergeJson(getTranslations(l), node.get(l));
            config.getTranslations().put(l, merged.toString());
        });
    } else {
        locales.forEach(l -> config.getTranslations().put(l, node.get(l).toString()));
    }
    micaConfigService.save(config);
    return Response.ok().build();
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(org.obiba.mica.core.domain.LocalizedString) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 4 with LocalizedString

use of org.obiba.mica.core.domain.LocalizedString in project mica2 by obiba.

the class ProjectService method getNextId.

private String getNextId(LocalizedString suggested) {
    if (suggested == null)
        return null;
    String prefix = suggested.asUrlSafeString().toLowerCase();
    if (Strings.isNullOrEmpty(prefix))
        return null;
    String next = prefix;
    if (!projectRepository.exists(next))
        return next;
    for (int i = 1; i <= 1000; i++) {
        next = prefix + "-" + i;
        if (!projectRepository.exists(next))
            return next;
    }
    return null;
}
Also used : LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 5 with LocalizedString

use of org.obiba.mica.core.domain.LocalizedString in project mica2 by obiba.

the class StudyIdGeneratorServiceTest method acronym.

private LocalizedString acronym(String englishId, String frenchId) {
    LocalizedString localizedString = acronym(englishId);
    localizedString.put(Locale.FRENCH, frenchId);
    return localizedString;
}
Also used : LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Aggregations

LocalizedString (org.obiba.mica.core.domain.LocalizedString)11 StudyTable (org.obiba.mica.core.domain.StudyTable)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 QueryParam (javax.ws.rs.QueryParam)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 NoSuchDatasetException (org.obiba.mica.dataset.NoSuchDatasetException)1 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)1 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)1 FileResource (org.obiba.mica.file.rest.FileResource)1