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