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