use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPArtefactManager method getArtefacts.
/**
* Used by the indexer to retrieve all the artefacts
* @param artefactIds List of ids to seek (optional)
* @param firstResult First position
* @param maxResults Max number of returned artefacts (0 or below for all)
* @return
*/
@SuppressWarnings("unchecked")
protected List<AbstractArtefact> getArtefacts(Identity author, List<Long> artefactIds, int firstResult, int maxResults) {
StringBuilder sb = new StringBuilder();
sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact");
boolean where = false;
if (author != null) {
where = true;
sb.append(" where artefact.author=:author");
}
if (artefactIds != null && !artefactIds.isEmpty()) {
if (where)
sb.append(" and ");
else
sb.append(" where ");
sb.append(" artefact.id in (:artefactIds)");
}
DBQuery query = dbInstance.createQuery(sb.toString());
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
if (firstResult >= 0) {
query.setFirstResult(firstResult);
}
if (author != null) {
query.setEntity("author", author);
}
if (artefactIds != null && !artefactIds.isEmpty()) {
query.setParameterList("artefactIds", artefactIds);
}
List<AbstractArtefact> artefacts = query.list();
return artefacts;
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPArtefactManager method filterArtefactsByString.
private void filterArtefactsByString(List<AbstractArtefact> artefacts, String textFilter) {
if (StringHelper.containsNonWhitespace(textFilter)) {
List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
for (AbstractArtefact artefact : artefacts) {
String textCompare = artefact.getTitle() + artefact.getDescription() + artefact.getFulltextContent();
if (!textCompare.toLowerCase().contains(textFilter.toLowerCase())) {
toRemove.add(artefact);
}
}
artefacts.removeAll(toRemove);
}
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPArtefactManager method filterArtefactsByDate.
/**
* date comparison will first set startDate to 00:00:00 and set endDate to
* 23:59:59 else there might be no results if start = end date. dateList must
* be set according to: dateList(0) = startDate dateList(1) = endDate
*/
private void filterArtefactsByDate(List<AbstractArtefact> artefacts, List<Date> dateList) {
if (dateList != null && dateList.size() != 0) {
if (dateList.size() == 2) {
Date startDate = dateList.get(0);
Date endDate = dateList.get(1);
Calendar cal = Calendar.getInstance();
if (startDate == null) {
cal.set(1970, 1, 1);
} else {
cal.setTime(startDate);
}
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
startDate = cal.getTime();
cal.setTime(endDate);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
endDate = cal.getTime();
List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
for (AbstractArtefact artefact : artefacts) {
Date creationDate = artefact.getCreationDate();
if (!(creationDate.before(endDate) && creationDate.after(startDate))) {
toRemove.add(artefact);
}
}
artefacts.removeAll(toRemove);
} else
throw new AssertException("provided DateList must contain exactly two Date-objects");
}
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPArtefactManager method filterArtefactsByType.
private void filterArtefactsByType(List<AbstractArtefact> artefacts, List<String> type) {
if (type != null && type.size() != 0) {
List<AbstractArtefact> toRemove = new ArrayList<AbstractArtefact>();
for (AbstractArtefact artefact : artefacts) {
if (!type.contains(artefact.getResourceableTypeName())) {
toRemove.add(artefact);
}
}
artefacts.removeAll(toRemove);
}
}
use of org.olat.portfolio.model.artefacts.AbstractArtefact in project OpenOLAT by OpenOLAT.
the class EPArtefactManager method createAndPersistArtefact.
/**
* Create and persist an artefact of the given type
*
* @param type
* @return The persisted artefact
*/
protected AbstractArtefact createAndPersistArtefact(Identity identity, String type) {
EPArtefactHandler<?> handler = portfolioModule.getArtefactHandler(type);
if (handler != null && handler.isEnabled()) {
AbstractArtefact artefact = handler.createArtefact();
artefact.setAuthor(identity);
dbInstance.saveObject(artefact);
saveArtefactFulltextContent(artefact);
return artefact;
} else {
return null;
}
}
Aggregations