/* (non-Javadoc) * @see kiwi.api.fragment.FragmentService#getContentItemFragments(kiwi.model.content.ContentItemI) */ @Override public <C extends FragmentFacade> Collection<C> getContentItemFragments( ContentItemI containing_ci, Class<C> type) { Collection<C> ret = new LinkedList<C>(); Collection<KiWiTriple> triples; try { triples = containing_ci .getResource() .listIncoming("http://www.kiwi-project.eu/kiwi/special/fragmentOf"); for (KiWiTriple triple : triples) { KiWiResource subject = triple.getSubject(); if (subject.isUriResource()) { KiWiUriResource subject_uri = (KiWiUriResource) triple.getSubject(); C ff = kiwiEntityManager.find(type, subject_uri.getUri()); if (ff != null) { ret.add(ff); } } } } catch (NamespaceResolvingException e) { e.printStackTrace(); } return ret; /*Query query = kiwiEntityManager.createQuery("SELECT ?B WHERE { ?B <http://www.kiwi-project.eu/kiwi/special/fragmentOf> <" + ((KiWiUriResource)containing_ci.getResource()).getUri() + "> . }", KiWiQueryLanguage.SPARQL, type); return query.getResultList();*/ }
/** computeUserSkills */ public void computeUserInteractivity() { if (deleteUserInteractivity()) { List<String> comparisions = new ArrayList<String>(); List<User> newWsers = new ArrayList<User>(); List<User> users = userService.getAllCreatedUsers(); newWsers = users; for (User user : newWsers) { for (User user2 : newWsers) { if (user != user2 && !comparisions.contains(user.getLogin() + user2.getLogin()) && !comparisions.contains(user2.getLogin() + user.getLogin())) { // System.out.println("computeUserInteractivity...USER 1 "+user.getFirstName()+" USER 2 // "+ user2.getFirstName()); float userInterctivityValue = computeUserInteractivity(user, user2); if (userInterctivityValue > 0f) { UserInteraction userInteraction = new UserInteraction(user, user2, userInterctivityValue); kiwiEntityManager.persist(userInteraction); // kiwiEntityManager.flush(); comparisions.add(user.getLogin() + user2.getLogin()); comparisions.add(user2.getLogin() + user.getLogin()); } } } } } }
public String showContentItemPresentation(ContentItem ci) { DkmsContentItemFacade contentItemFacade = kiwiEntityManager.createFacade(ci, DkmsContentItemFacade.class); dkmsContentItemBean.init(contentItemFacade); selectedDkmsContentItem = contentItemFacade; if (contentItemFacade.getDkmsContentItemType().equals("1")) { setContentItemTypeName("Simple Resource"); return "/edukms/abcmaths/exerciseSheetPresentation.xhtml"; } else if (contentItemFacade.getDkmsContentItemType().equals("2")) { setContentItemTypeName("Segmented Resource"); return "/edukms/abcmaths/sequencePresentation.xhtml"; } else if (contentItemFacade.getDkmsContentItemType().equals("3")) { setContentItemTypeName("Uploaded Resource"); return "/edukms/abcmaths/documentPresentation.xhtml"; } else if (contentItemFacade.getDkmsContentItemType().equals("4")) { setContentItemTypeName("Wiki Resource"); return "/edukms/abcmaths/wikiPresentation.xhtml"; } else if (contentItemFacade.getDkmsContentItemType().equals("5")) { setContentItemTypeName("Blog"); return "/edukms/abcmaths/blogPresentation.xhtml"; } else if (selectedDkmsContentItem.getDkmsContentItemType().equals("6")) { setContentItemTypeName("Combined Resource"); return "/edukms/abcmaths/combinedResourcesPresentation.xhtml"; } else return ""; }
public void removeContentItem(@Delete ContentItem item) { kiwiEntityManager.remove(item); Events.instance().raiseEvent(KiWiEvents.ACTIVITY_DELETECONTENTITEM, currentUser, item); Events.instance().raiseTransactionSuccessEvent(KiWiEvents.ITEM_REMOVED, item); // TODO add contentitem to updateTransactionBean }
// @TransactionAttribute(TransactionAttributeType.REQUIRED) @Override public ContentItem saveContentItem(@Update ContentItem item) { // TODO: this should rather be solved declaratively by an appropriate modification of @RDF item.getResource().setLabel(null, item.getTitle()); item.setModified(new Date()); // TODO: this method should raise an event to invalidate all caches that are // currently holding an instance of this content item if (item.getId() == null) { log.debug("Persisting new ContentItem #0 ", item); kiwiEntityManager.persist(item); } else if (!entityManager.contains(item)) { log.info("Merging ContentItem #0 ", item.getId()); item = entityManager.merge(item); } else { log.debug("Do nothing with ContentItem #0 ", item.getId()); } // if there is multimedia data in this content item, extract it... if (item.getMediaContent() != null) { MultimediaService ms = (MultimediaService) Component.getInstance("multimediaService"); ms.extractMetadata(item); } return item; }
public String save() { boolean error = checkValues(); // ... TODO KiWiProfileFacade currentProfile = profileService.getProfile(currentUser); // save values if (!error) { if (firstName != null) { currentProfile.setFirstName(firstName); } if (lastName != null) { currentProfile.setLastName(lastName); } if (gender != null) { currentProfile.setGender(gender); } if (birthday != null) { currentProfile.setBirthday(birthday); } if (email != null) { currentProfile.setEmail(email); } if (phone != null) { currentProfile.setPhone(phone); } if (mobile != null) { currentProfile.setMobile(mobile); } if (street != null) { currentProfile.setStreet(street); } if ((cityName != null)) { currentProfile.setCity(profileService.getCity(cityPostalCode, cityName, cityCountry)); } if (facebookAccount != null) { currentProfile.setFacebookAccount(facebookAccount); } if (twitterAccount != null) { currentProfile.setTwitterAccount(twitterAccount); } if (skypeAccount != null) { currentProfile.setSkype(skypeAccount); } currentProfile.setLongitude(longitude); currentProfile.setLatitude(latitude); contentItemService.updateTextContentItem(currentProfile, description); currentProfile.setInterests(profileService.getInterests(interests)); kiwiEntityManager.persist(currentProfile); } postSave(); return "profile_edited"; }
/** * @param item * @param user * @return */ private boolean isRatedByUser(ContentItem item, User user) { boolean isRated = false; final RatingFacade ratingF = kiwiEntityManager.createFacade(item, RatingFacade.class); for (RatingDataFacade ratingData : ratingF.getRatingDataFacades()) { if (user.equals(ratingData.getAuthor())) { isRated = true; } } return isRated; }
/* (non-Javadoc) * @see kiwi.api.fragment.FragmentService#getContentItemFragment(kiwi.model.content.ContentItemI, java.lang.String) */ @Override public <C extends FragmentFacade> C getContentItemFragment( ContentItemI containing_ci, String fragment_id, Class<C> type) { if (fragment_id.startsWith("uri::")) { String uri = fragment_id.substring("uri::".length()); C ff = kiwiEntityManager.find(type, uri); return ff; } return null; }
@Observer("userProfilePhotoRemove") public void onRemoveUserProfilePhoto() { log.info("userProfilePhotoRemove called, doing user-profile-photo specific persistence"); currentUser.setProfilePhoto(null); kiwiEntityManager.persist(currentUser); UserService us = (UserService) Component.getInstance("userService"); // us.saveUser(currentUser); profilePhoto = null; begin(); }
@Override public <C extends FragmentFacade> C createFragment(ContentItemI containing_ci, Class<C> type) { C ff = kiwiEntityManager.createFacade(contentItemService.createContentItem(), type); ff.setContainingContentItem(containing_ci.getDelegate()); ff.addType(tripleStore.createUriResource(Constants.NS_KIWI_SPECIAL + "Fragment")); for (KiWiTriple t : ff.getResource().listOutgoing()) { log.debug("triple: #0", t.toString()); } return ff; }
/* (non-Javadoc) * @see kiwi.api.fragment.FragmentService#createFragment(kiwi.model.content.ContentItemI, java.lang.String, java.lang.Class) */ @Override public <C extends FragmentFacade> C createFragment( ContentItemI containing_ci, String fragment_id, Class<C> type) { KiWiUriResource resource = createFragmentResource(fragment_id); // Create the facade log.debug("Creating fragment #0", resource.getKiwiIdentifier()); C ff = kiwiEntityManager.createFacade(resource.getContentItem(), type); ff.getDelegate().setDeleted(false); ff.setContainingContentItem(containing_ci.getDelegate()); ff.addType(tripleStore.createUriResource(Constants.NS_KIWI_SPECIAL + "Fragment")); for (KiWiTriple t : ff.getResource().listOutgoing()) { log.debug("triple: #0", t.toString()); } return ff; }
/** * @param user1 * @param user2 * @return content items authored by user1 rated by user2 */ @SuppressWarnings({"unused", "unchecked", "unchecked"}) private List<ContentItem> getUserRatingInteractivity(User user1, User user2) { List<ContentItem> result = new LinkedList<ContentItem>(); String s = "SELECT ?ci WHERE { " + " ?s <" + Constants.NS_RDF + "type> <" + Constants.NS_KIWI_CORE + "RatingData> . " + " ?s <" + Constants.NS_KIWI_CORE + "author> <" + user2.getResource() + "> . " + " ?s <" + Constants.NS_KIWI_CORE + "hasRatingFacade> ?ci . " + " ?ci <" + Constants.NS_KIWI_CORE + "author> <" + user1.getResource() + "> . }"; javax.persistence.Query q = kiwiEntityManager.createQuery(s, SPARQL, ContentItem.class); q.setHint("org.hibernate.cacheable", true); try { result = (List<ContentItem>) q.getResultList(); } catch (PersistenceException ex) { ex.printStackTrace(); log.warn("error while listing user Rating Interactivity: query failed"); } if (result == null) { return Collections.EMPTY_LIST; } else { return result; } }
// @Transactional // @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void importEntry( final SyndFeed feed, final SyndEntry entry, final Set<KiWiUriResource> types, final Set<ContentItem> tags, User user, final Collection<ContentItem> output) { if (user == null && entry.getAuthor() != null && !"".equals(entry.getAuthor())) { if (userService.userExists(entry.getAuthor())) { user = userService.getUserByLogin(entry.getAuthor()); } else { // user = userService.createUser(entry.getAuthor()); /* In my opinion, it is not ok to create a user entity * without asking the person if he/she wants to be * created and persisted in the KiWi dataset. * Thus I'm changing the user to 'anonymous', * if he/she is'nt registered with the same nick that * is given in the rss entry. */ user = userService.getUserByLogin("anonymous"); kiwiEntityManager.persist(user); } } log.debug("feed entry: #0 (#1)", entry.getTitle(), entry.getUri()); // create a new content item and copy all data from the feed entry ContentItem item; if (entry.getLink() != null) { item = contentItemService.createExternContentItem(entry.getLink()); } else if (entry.getUri() != null) { try { // try parsing URI; if it is not valid, URI uri = new URI(entry.getUri()); item = contentItemService.createExternContentItem(entry.getUri()); } catch (URISyntaxException e) { item = contentItemService.createExternContentItem(feed.getLink() + "#" + entry.getUri()); } } else { item = contentItemService.createContentItem(); } contentItemService.updateTitle(item, entry.getTitle()); if (feed.getLanguage() != null) item.setLanguage(new Locale(feed.getLanguage())); if (entry.getPublishedDate() != null) { item.setCreated(entry.getPublishedDate()); item.setModified(entry.getPublishedDate()); } if (entry.getUpdatedDate() != null) { if (entry.getPublishedDate() == null) { item.setCreated(entry.getUpdatedDate()); } item.setModified(entry.getUpdatedDate()); } item.setAuthor(user); // read feed content and set it as item's text content List<SyndContent> contents = entry.getContents(); if (contents.size() == 1) { log.debug("using RSS content section provided by item"); contentItemService.updateTextContentItem(item, "<p>" + contents.get(0).getValue() + "</p>"); } else if (contents.size() > 1) { log.warn("feed entry contained more than one content section"); contentItemService.updateTextContentItem(item, "<p>" + contents.get(0).getValue() + "</p>"); } else if (contents.size() == 0) { if (entry.getDescription() != null && entry.getDescription().getValue() != null) { log.debug("using RSS description as no content section was available"); contentItemService.updateTextContentItem( item, "<p>" + entry.getDescription().getValue() + "</p>"); } } // save before tagging contentItemService.saveContentItem(item); // read feed categories and use them as tags for (SyndCategory cat : (List<SyndCategory>) entry.getCategories()) { ContentItem _cat; if (!taggingService.hasTag(item, cat.getName())) { if (cat.getTaxonomyUri() != null) { _cat = contentItemService.getContentItemByUri(cat.getTaxonomyUri()); if (_cat == null) { _cat = contentItemService.createExternContentItem(cat.getTaxonomyUri()); contentItemService.updateTitle(_cat, cat.getName()); _cat.setAuthor(user); contentItemService.saveContentItem(_cat); } taggingService.createTagging(cat.getName(), item, _cat, user); } else { _cat = contentItemService.getContentItemByTitle(cat.getName()); if (_cat == null) { _cat = contentItemService.createContentItem(); contentItemService.updateTitle(_cat, cat.getName()); _cat.setAuthor(user); contentItemService.saveContentItem(_cat); } taggingService.createTagging(cat.getName(), item, _cat, user); } } } // scan for Twitter-style hash tags in title (e.g. #kiwiknows, see KIWI-622) Matcher m_hashtag = p_hashtag.matcher(entry.getTitle()); while (m_hashtag.find()) { String tag_label = m_hashtag.group(1); if (!taggingService.hasTag(item, tag_label)) { ContentItem tag = contentItemService.getContentItemByTitle(tag_label); if (tag == null) { tag = contentItemService.createContentItem(); contentItemService.updateTitle(tag, tag_label); tag.setAuthor(user); contentItemService.saveContentItem(tag); } taggingService.createTagging(tag_label, item, tag, user); } } // check for geo information GeoRSSModule geoRSSModule = GeoRSSUtils.getGeoRSS(entry); if (geoRSSModule != null && geoRSSModule.getPosition() != null) { POI poi = kiwiEntityManager.createFacade(item, POI.class); poi.setLatitude(geoRSSModule.getPosition().getLatitude()); poi.setLongitude(geoRSSModule.getPosition().getLongitude()); kiwiEntityManager.persist(poi); } // check for media information MediaEntryModule mediaModule = (MediaEntryModule) entry.getModule(MediaModule.URI); if (mediaModule != null) { MediaContent[] media = mediaModule.getMediaContents(); if (media.length > 0) { MediaContent m = media[0]; if (m.getReference() instanceof UrlReference) { URL url = ((UrlReference) m.getReference()).getUrl(); String type = m.getType(); String name = url.getFile(); if (name.lastIndexOf("/") > 0) { name = name.substring(name.lastIndexOf("/") + 1); } log.debug("importing media data from URL #0", url.toString()); try { InputStream is = url.openStream(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); int c; while ((c = is.read()) != -1) { bout.write(c); } byte[] data = bout.toByteArray(); contentItemService.updateMediaContentItem(item, data, type, name); is.close(); bout.close(); } catch (IOException ex) { log.error("error importing media content from RSS stream"); } } else { log.info("RSS importer can only import media with URL references"); } } else { log.warn("media module found without content"); } Category[] cats = mediaModule.getMetadata().getCategories(); for (Category cat : cats) { ContentItem _cat; String label = cat.getLabel() != null ? cat.getLabel() : cat.getValue(); if (!taggingService.hasTag(item, label)) { if (cat.getScheme() != null) { _cat = contentItemService.getContentItemByUri(cat.getScheme() + cat.getValue()); if (_cat == null) { _cat = contentItemService.createExternContentItem(cat.getScheme() + cat.getValue()); contentItemService.updateTitle(_cat, label); _cat.setAuthor(user); contentItemService.saveContentItem(_cat); } taggingService.createTagging(label, item, _cat, user); } else { _cat = contentItemService.getContentItemByTitle(label); if (_cat == null) { _cat = contentItemService.createContentItem(); contentItemService.updateTitle(_cat, label); _cat.setAuthor(user); contentItemService.saveContentItem(_cat); } taggingService.createTagging(label, item, _cat, user); } } } } // add parameter categories as tags for (ContentItem tag : tags) { if (!taggingService.hasTag(item, tag.getTitle())) { taggingService.createTagging(tag.getTitle(), item, tag, user); } } // add parameter types as types for (KiWiUriResource type : types) { item.addType(type); } // add kiwi:FeedPost type item.addType(tripleStore.createUriResource(Constants.NS_KIWI_CORE + "FeedPost")); /* the flush is necessary, because CIs or tags will * otherwise be created multiple times when they * appear more than once in one RSS feed */ entityManager.flush(); log.debug("imported content item '#0' with URI '#1'", item.getTitle(), item.getResource()); }
/* (non-Javadoc) * @see kiwi.api.fragment.FragmentService#removeFragment(kiwi.api.fragment.FragmentFacade) */ @Override public void removeFragment(FragmentFacade ff) { kiwiEntityManager.remove(ff.getDelegate()); }
/* (non-Javadoc) * @see kiwi.api.fragment.FragmentService#saveFragment(kiwi.api.fragment.FragmentFacade) */ @Override public void saveFragment(FragmentFacade ff) { kiwiEntityManager.persist(ff.getDelegate()); }