Search in sources :

Example 1 with SetOperation

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

the class SetOperationService method create.

/**
 * Create all possible sub-sets from the provided {@link DocumentSet} (maximum of 3) plus the union of all.
 *
 * @param sets
 * @return
 */
public SetOperation create(List<DocumentSet> sets) {
    if (sets.isEmpty())
        throw new IllegalArgumentException("Sets to compose are missing");
    if (sets.size() == 1)
        throw new IllegalArgumentException("Cannot compose a single set");
    if (sets.size() > 3)
        throw new IllegalArgumentException("Cannot compose more than 3 sets");
    for (DocumentSet set : sets) {
        if (!getType().equals(set.getType()))
            throw new IllegalArgumentException("Wrong set type: " + set.getType() + ", expecting " + getType());
    }
    SetOperation setOperation = new SetOperation();
    setOperation.setType(getType());
    setOperation.setLastModifiedDate(DateTime.now());
    Object principal = SecurityUtils.getSubject().getPrincipal();
    if (principal != null) {
        setOperation.setUsername(principal.toString());
    }
    List<String> operands = sets.stream().map(DocumentSet::getId).collect(Collectors.toList());
    setOperation.addComposition(createUnion(operands));
    setOperation.addComposition(createInter(operands));
    if (operands.size() == 2) {
        setOperation.addComposition(createDiff12(operands));
        setOperation.addComposition(createDiff21(operands));
    } else {
        setOperation.addComposition(createDiffInter123(operands));
        setOperation.addComposition(createDiffInter231(operands));
        setOperation.addComposition(createDiffInter312(operands));
        setOperation.addComposition(createDiffUnion123(operands));
        setOperation.addComposition(createDiffUnion231(operands));
        setOperation.addComposition(createDiffUnion312(operands));
    }
    return save(setOperation);
}
Also used : SetOperation(org.obiba.mica.core.domain.SetOperation) DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 2 with SetOperation

use of org.obiba.mica.core.domain.SetOperation 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)

Aggregations

DocumentSet (org.obiba.mica.core.domain.DocumentSet)2 SetOperation (org.obiba.mica.core.domain.SetOperation)2 AuthorizationException (org.apache.shiro.authz.AuthorizationException)1