Search in sources :

Example 31 with DocumentSet

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

the class CartController method getNamed.

@GetMapping("/list/{id:.+}")
public ModelAndView getNamed(@PathVariable String id) {
    MicaConfig config = micaConfigService.getConfig();
    if (!config.isCartEnabled()) {
        return new ModelAndView("redirect:/");
    }
    Subject subject = SecurityUtils.getSubject();
    if (subject.isAuthenticated()) {
        DocumentSet documentSet = variableSetService.get(id);
        if (!subjectAclService.isCurrentUser(documentSet.getUsername()) && !subjectAclService.isAdministrator() && !subjectAclService.isDataAccessOfficer())
            throw new ForbiddenException();
        Map<String, Object> params = newParameters();
        params.put("set", documentSet);
        return new ModelAndView("list", params);
    } else {
        return new ModelAndView("redirect:/signin?redirect=" + micaConfigService.getContextPath() + "/list/" + id);
    }
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) ForbiddenException(javax.ws.rs.ForbiddenException) ModelAndView(org.springframework.web.servlet.ModelAndView) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Subject(org.apache.shiro.subject.Subject) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 32 with DocumentSet

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

the class CartController method lists.

@GetMapping("/lists")
public ModelAndView lists() {
    MicaConfig config = micaConfigService.getConfig();
    if (!config.isCartEnabled()) {
        return new ModelAndView("redirect:/");
    }
    Subject subject = SecurityUtils.getSubject();
    if (subject.isAuthenticated()) {
        Optional<DocumentSet> tentative = variableSetService.getAllCurrentUser().stream().filter(DocumentSet::hasName).findFirst();
        return tentative.map(documentSet -> new ModelAndView("redirect:/list/" + documentSet.getId())).orElseGet(() -> new ModelAndView("redirect:/search"));
    } else {
        return new ModelAndView("redirect:signin?redirect=" + micaConfigService.getContextPath() + "/lists");
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) RequestParam(org.springframework.web.bind.annotation.RequestParam) ForbiddenException(javax.ws.rs.ForbiddenException) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) Controller(org.springframework.stereotype.Controller) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ModelAndView(org.springframework.web.servlet.ModelAndView) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Lists(com.google.common.collect.Lists) Subject(org.apache.shiro.subject.Subject) Map(java.util.Map) DataAccessConfigService(org.obiba.mica.micaConfig.service.DataAccessConfigService) GetMapping(org.springframework.web.bind.annotation.GetMapping) Optional(java.util.Optional) SecurityUtils(org.apache.shiro.SecurityUtils) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Subject(org.apache.shiro.subject.Subject) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 33 with DocumentSet

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

the class PublishedDatasetVariablesSetsResource method compose.

@POST
@Path("operations")
public Response compose(@Context UriInfo uriInfo, @QueryParam("s1") String set1, @QueryParam("s2") String set2, @QueryParam("s3") String set3) {
    if (!subjectAclService.hasMicaRole())
        throw new AuthorizationException();
    List<DocumentSet> sets = Lists.newArrayList();
    sets.add(variableSetService.get(set1));
    sets.add(variableSetService.get(set2));
    if (!Strings.isNullOrEmpty(set3))
        sets.add(variableSetService.get(set3));
    SetOperation setOperation = variableSetOperationService.create(sets);
    return Response.created(uriInfo.getBaseUriBuilder().segment("variables", "sets", "operation", setOperation.getId()).build()).build();
}
Also used : SetOperation(org.obiba.mica.core.domain.SetOperation) AuthorizationException(org.apache.shiro.authz.AuthorizationException) DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 34 with DocumentSet

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

the class PublishedDatasetVariablesSetResource method importQueryVariables.

@POST
@Path("/documents/_rql")
public Response importQueryVariables(@FormParam("query") String query) throws IOException {
    DocumentSet set = variableSetService.get(id);
    if (Strings.isNullOrEmpty(query))
        return Response.ok().entity(dtos.asDto(set)).build();
    MicaSearch.JoinQueryResultDto result = joinQueryExecutor.query(QueryType.VARIABLE, searcher.makeJoinQuery(query));
    if (result.hasVariableResultDto() && result.getVariableResultDto().getTotalHits() > 0) {
        List<String> ids = result.getVariableResultDto().getExtension(MicaSearch.DatasetVariableResultDto.result).getSummariesList().stream().map(Mica.DatasetVariableResolverDto::getId).collect(Collectors.toList());
        variableSetService.addIdentifiers(id, ids);
        set = variableSetService.get(id);
    }
    return Response.ok().entity(dtos.asDto(set)).build();
}
Also used : MicaSearch(org.obiba.mica.web.model.MicaSearch) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Mica(org.obiba.mica.web.model.Mica)

Example 35 with DocumentSet

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

the class PublishedDatasetVariablesSetResource method exportVariables.

@GET
@Path("/documents/_export")
@Produces(MediaType.TEXT_PLAIN)
public Response exportVariables() {
    DocumentSet documentSet = variableSetService.get(id);
    StreamingOutput stream = os -> {
        documentSet.getIdentifiers().forEach(id -> {
            try {
                os.write((id + "\n").getBytes());
            } catch (IOException e) {
            // ignore
            }
        });
        os.flush();
    };
    return Response.ok(stream).header("Content-Disposition", String.format("attachment; filename=\"%s-variables.txt\"", id)).build();
}
Also used : Searcher(org.obiba.mica.spi.search.Searcher) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) DocumentSet(org.obiba.mica.core.domain.DocumentSet) JoinQueryExecutor(org.obiba.mica.search.JoinQueryExecutor) MicaSearch(org.obiba.mica.web.model.MicaSearch) Component(org.springframework.stereotype.Component) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) Lists(com.google.common.collect.Lists) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) QueryType(org.obiba.mica.spi.search.QueryType) Mica(org.obiba.mica.web.model.Mica) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Dtos(org.obiba.mica.web.model.Dtos) StreamingOutput(javax.ws.rs.core.StreamingOutput) DocumentSet(org.obiba.mica.core.domain.DocumentSet) IOException(java.io.IOException)

Aggregations

DocumentSet (org.obiba.mica.core.domain.DocumentSet)35 Lists (com.google.common.collect.Lists)7 List (java.util.List)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 StreamingOutput (javax.ws.rs.core.StreamingOutput)5 VariableSetService (org.obiba.mica.dataset.service.VariableSetService)5 Mica (org.obiba.mica.web.model.Mica)5 MicaSearch (org.obiba.mica.web.model.MicaSearch)5 Component (org.springframework.stereotype.Component)5 Subscribe (com.google.common.eventbus.Subscribe)4 ForbiddenException (javax.ws.rs.ForbiddenException)4 Strings (com.google.common.base.Strings)3 SecurityUtils (org.apache.shiro.SecurityUtils)3 AuthorizationException (org.apache.shiro.authz.AuthorizationException)3 Subject (org.apache.shiro.subject.Subject)3 DocumentSetUpdatedEvent (org.obiba.mica.core.event.DocumentSetUpdatedEvent)3 ReportGenerator (org.obiba.mica.search.reports.ReportGenerator)3 Logger (org.slf4j.Logger)3