use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class AuthoringEntryDataSource method processViewModel.
private List<AuthoringEntryRow> processViewModel(List<RepositoryEntryAuthorView> repoEntries) {
Set<String> newNames = new HashSet<>();
List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
for (RepositoryEntryAuthorView entry : repoEntries) {
if (entry.isOfferAvailable()) {
resourcesWithAC.add(entry.getOlatResource());
}
final String author = entry.getAuthor();
if (StringHelper.containsNonWhitespace(author)) {
newNames.add(author);
}
}
Map<String, String> fullNames = userManager.getUserDisplayNamesByUserName(newNames);
List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
Collection<OLATResourceable> resources = repoEntries.stream().map(RepositoryEntryAuthorView::getOlatResource).collect(Collectors.toList());
List<ResourceLicense> licenses = licenseService.loadLicenses(resources);
List<AuthoringEntryRow> items = new ArrayList<>();
for (RepositoryEntryAuthorView entry : repoEntries) {
String fullname = fullNames.get(entry.getAuthor());
if (fullname == null) {
fullname = entry.getAuthor();
}
AuthoringEntryRow row = new AuthoringEntryRow(entry, fullname);
// bookmark
row.setMarked(entry.isMarked());
// access control
List<PriceMethod> types = new ArrayList<>();
if (entry.isMembersOnly()) {
// members only always show lock icon
types.add(new PriceMethod("", "o_ac_membersonly_icon", uifactory.getTranslator().translate("cif.access.membersonly.short")));
} else {
// collect access control method icons
OLATResource resource = entry.getOlatResource();
for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
String displayName = amh.getMethodName(uifactory.getTranslator().getLocale());
types.add(new PriceMethod(price, type, displayName));
}
}
}
}
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
// license
for (ResourceLicense license : licenses) {
OLATResource resource = entry.getOlatResource();
if (license.getResId().equals(resource.getResourceableId()) && license.getResName().equals(resource.getResourceableTypeName())) {
row.setLicense(license);
}
}
uifactory.forgeLinks(row);
items.add(row);
}
return items;
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class QuestionItemDocumentFactory method createDocument.
public Document createDocument(SearchResourceContext searchResourceContext, QuestionItemFull item) {
OlatDocument oDocument = new OlatDocument();
oDocument.setId(item.getKey());
oDocument.setCreatedDate(item.getCreationDate());
oDocument.setLastChange(item.getLastModified());
oDocument.setTitle(item.getTitle());
oDocument.setDescription(item.getDescription());
oDocument.setResourceUrl(getResourceUrl(item.getKey()));
oDocument.setDocumentType(QItemDocument.TYPE);
oDocument.setCssIcon("o_qitem_icon");
oDocument.setParentContextType(searchResourceContext.getParentContextType());
oDocument.setParentContextName(searchResourceContext.getParentContextName());
// author
StringBuilder authorSb = new StringBuilder();
List<Identity> owners = qpoolService.getAuthors(item);
for (Identity owner : owners) {
User user = owner.getUser();
authorSb.append(user.getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(user.getProperty(UserConstants.LASTNAME, null)).append(" ");
}
oDocument.setAuthor(authorSb.toString());
// add specific fields
Document document = oDocument.getLuceneDocument();
// content
QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
if (provider != null) {
String content = provider.extractTextContent(item);
if (content != null) {
addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content, 0.8f);
}
}
if (item.getDescription() != null) {
addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription(), 1.0f);
}
// general fields
addStringField(document, QItemDocument.IDENTIFIER_FIELD, item.getIdentifier(), 1.0f);
addStringField(document, QItemDocument.MASTER_IDENTIFIER_FIELD, item.getMasterIdentifier(), 1.0f);
addTextField(document, QItemDocument.KEYWORDS_FIELD, item.getKeywords(), 2.0f);
addTextField(document, QItemDocument.COVERAGE_FIELD, item.getCoverage(), 2.0f);
addTextField(document, QItemDocument.ADD_INFOS_FIELD, item.getAdditionalInformations(), 2.0f);
addStringField(document, QItemDocument.LANGUAGE_FIELD, item.getLanguage(), 1.0f);
addTextField(document, QItemDocument.TOPIC_FIELD, item.getTopic(), 2.0f);
// educational
if (qpoolModule.isEducationalContextEnabled()) {
if (item.getEducationalContext() != null) {
String context = item.getEducationalContext().getLevel();
addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context, 1.0f);
}
}
// question
if (item.getType() != null) {
String itemType = item.getType().getType();
addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType, 1.0f);
}
addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType(), 1.0f);
// lifecycle
addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion(), 1.0f);
if (item.getQuestionStatus() != null) {
addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name(), 1.0f);
}
// rights
ResourceLicense license = licenseService.loadLicense(item);
if (license != null && license.getLicenseType() != null) {
String licenseKey = String.valueOf(license.getLicenseType().getKey());
addTextField(document, QItemDocument.LICENSE_TYPE_FIELD_NAME, licenseKey, 2.0f);
}
// technical
addTextField(document, QItemDocument.EDITOR_FIELD, item.getEditor(), 2.0f);
addStringField(document, QItemDocument.EDITOR_VERSION_FIELD, item.getEditorVersion(), 1.0f);
addStringField(document, QItemDocument.FORMAT_FIELD, item.getFormat(), 1.0f);
// save owners key
for (Identity owner : owners) {
document.add(new StringField(QItemDocument.OWNER_FIELD, owner.getKey().toString(), Field.Store.NO));
}
// link resources
List<OLATResource> resources = questionItemDao.getSharedResources(item);
for (OLATResource resource : resources) {
document.add(new StringField(QItemDocument.SHARE_FIELD, resource.getKey().toString(), Field.Store.NO));
}
// need pools
List<Pool> pools = poolDao.getPools(item);
for (Pool pool : pools) {
document.add(new StringField(QItemDocument.POOL_FIELD, pool.getKey().toString(), Field.Store.NO));
}
// need path
if (qpoolModule.isTaxonomyEnabled()) {
String path = item.getTaxonomicPath();
if (StringHelper.containsNonWhitespace(path)) {
for (StringTokenizer tokenizer = new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) {
String nextToken = tokenizer.nextToken();
document.add(new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, nextToken, Field.Store.NO));
}
if (item instanceof QuestionItemImpl) {
Long key = ((QuestionItemImpl) item).getTaxonomyLevel().getKey();
TextField field = new TextField(QItemDocument.TAXONOMIC_FIELD, key.toString(), Field.Store.YES);
field.setBoost(3.0f);
document.add(field);
}
}
}
return document;
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class ManifestMetadataBuilder method appendMetadataFrom.
/**
* This method will add new metadata to the current ones.
*
* @param item
* @param locale
*/
public void appendMetadataFrom(QuestionItem item, AssessmentItem assessmentItem, Locale locale) {
String lang = item.getLanguage();
if (!StringHelper.containsNonWhitespace(lang)) {
lang = locale.getLanguage();
}
// LOM : General
if (StringHelper.containsNonWhitespace(item.getTitle())) {
setTitle(item.getTitle(), lang);
}
if (StringHelper.containsNonWhitespace(item.getCoverage())) {
setCoverage(item.getCoverage(), lang);
}
if (StringHelper.containsNonWhitespace(item.getKeywords())) {
setGeneralKeywords(item.getKeywords(), lang);
}
if (StringHelper.containsNonWhitespace(item.getDescription())) {
setDescription(item.getDescription(), lang);
}
// LOM : Technical
setTechnicalFormat(ManifestBuilder.ASSESSMENTITEM_MIMETYPE);
// LOM : Educational
if (StringHelper.containsNonWhitespace(item.getEducationalContextLevel())) {
setEducationalContext(item.getEducationalContextLevel(), lang);
}
if (StringHelper.containsNonWhitespace(item.getEducationalLearningTime())) {
setEducationalLearningTime(item.getEducationalLearningTime());
}
if (item.getLanguage() != null) {
setLanguage(item.getLanguage(), lang);
}
// LOM : Lifecycle
if (StringHelper.containsNonWhitespace(item.getItemVersion())) {
setLifecycleVersion(item.getItemVersion());
}
// LOM : Rights
LicenseService lService = CoreSpringFactory.getImpl(LicenseService.class);
ResourceLicense license = lService.loadLicense(item);
if (license != null) {
String licenseText = null;
LicenseType licenseType = license.getLicenseType();
if (lService.isFreetext(licenseType)) {
licenseText = license.getFreetext();
} else if (!lService.isNoLicense(licenseType)) {
licenseText = license.getLicenseType().getName();
}
if (StringHelper.containsNonWhitespace(licenseText)) {
setLicense(licenseText);
}
setOpenOLATMetadataCreator(license.getLicensor());
}
// LOM : classification
if (StringHelper.containsNonWhitespace(item.getTaxonomicPath())) {
setClassificationTaxonomy(item.getTaxonomicPath(), lang);
}
// QTI 2.1
setQtiMetadataTool(item.getEditor(), null, item.getEditorVersion());
if (assessmentItem != null) {
List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
List<String> interactionNames = new ArrayList<>(interactions.size());
for (Interaction interaction : interactions) {
interactionNames.add(interaction.getQtiClassName());
}
setQtiMetadataInteractionTypes(interactionNames);
}
// OpenOLAT
if (item.getType() != null) {
setOpenOLATMetadataQuestionType(item.getType().getType());
} else {
setOpenOLATMetadataQuestionType(null);
}
setOpenOLATMetadataIdentifier(item.getIdentifier());
setOpenOLATMetadataDifficulty(item.getDifficulty());
setOpenOLATMetadataDiscriminationIndex(item.getDifferentiation());
setOpenOLATMetadataDistractors(item.getNumOfAnswerAlternatives());
setOpenOLATMetadataStandardDeviation(item.getStdevDifficulty());
setOpenOLATMetadataUsage(item.getUsage());
setOpenOLATMetadataAssessmentType(item.getAssessmentType());
setOpenOLATMetadataTopic(item.getTopic());
setOpenOLATMetadataAdditionalInformations(item.getAdditionalInformations());
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_12_4_0 method saveFreetextLicense.
private void saveFreetextLicense(QuestionItemImpl item) {
QLicense qlicense = item.getLicense();
ResourceLicense license = licenseService.loadOrCreateLicense(item);
license.setLicenseType(getFreetextLicenseType());
license.setFreetext(qlicense.getLicenseText());
license.setLicensor(item.getCreator());
licenseService.update(license);
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class RepositoryEntryImportExport method addLicenseInformations.
private void addLicenseInformations(RepositoryEntryImport imp, RepositoryEntry re) {
LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
ResourceLicense license = licenseService.loadLicense(re.getOlatResource());
if (license != null) {
imp.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
imp.setLicenseTypeName(license.getLicenseType().getName());
imp.setLicensor(license.getLicensor());
imp.setLicenseText(LicenseUIFactory.getLicenseText(license));
}
}
Aggregations