Search in sources :

Example 21 with DocumentSet

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

the class DocumentSetService method addIdentifiers.

/**
 * Add identifiers to a set.
 *
 * @param id
 * @param identifiers
 * @return
 */
public DocumentSet addIdentifiers(String id, List<String> identifiers) {
    DocumentSet documentSet = get(id);
    if (identifiers.isEmpty())
        return documentSet;
    List<String> concatenatedIdentifiers = Stream.concat(documentSet.getIdentifiers().stream(), identifiers.stream()).distinct().limit(micaConfigService.getConfig().getMaxItemsPerSet()).collect(Collectors.toList());
    documentSet.setIdentifiers(concatenatedIdentifiers);
    return save(documentSet, null);
}
Also used : DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 22 with DocumentSet

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

the class DocumentSetService method create.

/**
 * Create a set of documents associated to the current user.
 *
 * @param name
 * @param identifiers
 * @return
 */
public DocumentSet create(@Nullable String name, List<String> identifiers) {
    DocumentSet documentSet = new DocumentSet();
    if (!Strings.isNullOrEmpty(name))
        documentSet.setName(name);
    documentSet.setIdentifiers(identifiers);
    documentSet.setType(getType());
    return save(documentSet, null);
}
Also used : DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 23 with DocumentSet

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

the class DocumentSetService method removeIdentifiers.

/**
 * Remove the given identifiers from the document set and notify about the removal.
 *
 * @param id
 * @param identifiers
 * @return
 */
public DocumentSet removeIdentifiers(String id, List<String> identifiers) {
    DocumentSet documentSet = get(id);
    if (identifiers.isEmpty())
        return documentSet;
    documentSet.getIdentifiers().removeAll(identifiers);
    return save(documentSet, Sets.newLinkedHashSet(identifiers));
}
Also used : DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 24 with DocumentSet

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

the class DocumentSetService method get.

/**
 * Get document with ID and ensure the type is valid.
 *
 * @param id
 * @return
 */
public DocumentSet get(String id) {
    DocumentSet documentSet = findOne(id);
    ensureType(documentSet);
    return documentSet;
}
Also used : DocumentSet(org.obiba.mica.core.domain.DocumentSet)

Example 25 with DocumentSet

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

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