Exemplo n.º 1
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTextContentItem(ContentItemI item, String content) {

    ContentItem _item = item.getDelegate();

    if (renderingPipeline.renderEditor(_item, currentUser).equals(content)) {
      log.error("!!!!!!!!!!!!!!!!! renderingPipeline fails");
      return;
      // throw new TextContentNotChangedException("Could not create TextContentUpdate for an
      // unchanged text content");
    }
    StoringService storingPipeline = (StoringService) Component.getInstance("storingPipeline");

    TextContent tc = new TextContent(_item);
    tc.setXmlString(storingPipeline.processHtmlSource(_item.getResource(), content));
    tc = storingPipeline.processTextContent(_item.getResource(), tc);

    entityManager.persist(tc);

    // TODO: check whether content has changed and create version
    // TODO: maybe we can check this even before the pipeline runs?
    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(_item, tc);
    }

    _item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, _item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, _item);
  }
Exemplo n.º 2
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTextContentWithoutStoringPipeline(ContentItemI item, String content)
      throws TextContentNotChangedException {

    ContentItem _item = item.getDelegate();

    if (renderingPipeline.renderEditor(_item, currentUser).equals(content)) {
      log.error("!!!!!!!!!!!!!!!!! renderingPipeline fails");
      throw new TextContentNotChangedException(
          "Could not create TextContentUpdate for an unchanged text content");
    }

    TextContent tc = new TextContent(_item);
    // TODO: can this cause some damage? Maybe we should at least do some regex checking
    tc.setXmlString(content);

    // TODO: check whether content has changed and create version
    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(_item, tc);
    }

    _item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, _item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, _item);
  }
Exemplo n.º 3
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTextContentItem(ContentItemI item, Document content) {
    ContentItem _item = item.getDelegate();

    TextContent tc = new TextContent(_item);
    tc.setXmlDocument(content);

    // To check if the content has changed, check whether both contents produce the same output for
    // the editor
    if (_item.getTextContent() != null
        && _item.getTextContent().getXmlString(true).equals(tc.getXmlString(true))) {
      log.error("!!!!!!!!!!!!!!!!! renderingPipeline fails");
      return;
      // throw new TextContentNotChangedException("Could not create TextContentUpdate for an
      // unchanged text content");
    }
    entityManager.persist(tc);

    // TODO: check whether content has changed and create version
    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(_item, tc);
    }

    _item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, _item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, _item);
  }
Exemplo n.º 4
0
  /**
   * Create a new non-local content item (i.e. with a URI that does not resolve to the current
   * system's base URI.
   *
   * <p>This method does not call persist, the created content item must be persisted manually.
   *
   * @param uri the uri of the external content item to create
   * @return a newly initialised content item that can be used for further operations
   */
  @Insert(ContentItem.class)
  public ContentItem createExternContentItem(String uri) {
    ContentItem result = getContentItemByUri(uri);
    if (result == null) {
      result = tripleStore.createUriResource(uri).getContentItem();
      result.setAuthor(currentUser);

      // TODO: workaround, needs to be fixed properly (KIWI-684)
      //			transactionService.getCurrentTransactionData().setCurrentContentItem(result);

      Events.instance().raiseEvent(KiWiEvents.ACTIVITY_CREATECONTENTITEM, currentUser, result);
      Events.instance().raiseTransactionSuccessEvent(KiWiEvents.ITEM_CREATED, result);
    }
    return result;
  }
Exemplo n.º 5
0
  public List<ReferencesNode> getIncoming() {
    if (incoming == null) {
      incoming = new ArrayList<ReferencesNode>();

      // get incoming triples up to limit
      Collection<KiWiTriple> incomingTriples;
      try {
        incomingTriples = currentContentItem.getResource().listIncoming(null, limit);
      } catch (NamespaceResolvingException e) {
        e.printStackTrace();
        incomingTriples = Collections.emptySet();
      }
      incomingCount = incomingTriples.size();

      Map<KiWiResource, List<KiWiTriple>> groupings = calculateGrouping(incomingTriples);

      for (KiWiResource prop : groupings.keySet()) {
        // create new node for property
        ReferencesNode node = new ReferencesNode(prop);
        incoming.add(node);

        // add all objects reachable by this property to the children of the node
        for (KiWiTriple t : groupings.get(prop)) {
          ReferencesNode child = new ReferencesNode((KiWiResource) t.getSubject());
          if (t.isInferred()) {
            child.setInferred(true);
          }
          child.setTripleId(t.getId());
          node.getChildren().add(child);
        }
      }
    }
    return incoming;
  }
Exemplo n.º 6
0
 public void init() {
   log.debug("Initializing StyleCreator");
   versions = currentContentItem.getVersions();
   if (versions == null) {
     return;
   }
   if (perRevision) {
     numberOfColours = versions.size();
   } else {
     HashMap<String, Set<CIVersion>> styles = new HashMap<String, Set<CIVersion>>();
     for (CIVersion v : versions) {
       if (v.getTextContentUpdate() != null) {
         User user = v.getRevision().getUser();
         if (!styles.containsKey(user.getLogin())) {
           Set<CIVersion> revSet = new HashSet<CIVersion>();
           revSet.add(v);
           styles.put(user.getLogin(), revSet);
         } else {
           Set<CIVersion> revSet = styles.get(user.getLogin());
           revSet.add(v);
         }
       }
     }
     this.styles = styles;
     numberOfColours = styles.size();
   }
 }
Exemplo n.º 7
0
  public void addTopContribution(ContentItem topContribution) throws JSONException {
    HashMap<String, Object> topContributionMap = new HashMap<String, Object>();
    topContributionMap.put("uri", getCIUri(topContribution));
    topContributionMap.put("title", topContribution.getTitle());

    topContributions.add(topContributionMap);
    put("top_contributions", topContributions);
  }
Exemplo n.º 8
0
 /**
  * TODO: Check whether this method already exist and remove this.
  *
  * @param contentItem
  * @return
  */
 @SuppressWarnings("unchecked")
 public List<String> getTagLabelsByContentItemAndAuthor(ContentItem contentItem, User user) {
   javax.persistence.Query q =
       entityManager.createNamedQuery("contentItemService.getTagLabelsByContentItemAndAuthor");
   q.setParameter("contentItemId", contentItem.getId());
   q.setParameter("author", user);
   return q.getResultList();
 }
Exemplo n.º 9
0
  //	@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;
  }
Exemplo n.º 10
0
  public void writeTo(
      ContentItem st,
      Class<?> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, Object> httpHeaders,
      java.io.OutputStream entityStream)
      throws IOException, WebApplicationException {

    TripleStore tripleStore = (TripleStore) Component.getInstance("tripleStore");

    log.info("Titel in Writer" + st.getTitle());

    if (tripleStore == null) {
      log.info("Triplestore not initialized");
    }

    tripleStore.exportData(entityStream, st.getResource(), KiWiDataFormat.RDFXML);
  }
Exemplo n.º 11
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  @Override
  public ContentItem createTextContentItem(String content) {
    ContentItem item = createContentItem();

    StoringService storingPipeline = (StoringService) Component.getInstance("storingPipeline");

    TextContent tc = new TextContent(item);
    tc.setXmlString(storingPipeline.processHtmlSource(item.getResource(), content));
    tc = storingPipeline.processTextContent(item.getResource(), tc);
    entityManager.persist(tc);

    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(item, tc);
    }

    item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, item);
    return item;
  }
Exemplo n.º 12
0
  @Observer("userProfilePhotoSave")
  public void onSaveUserProfilePhoto()
      throws SecurityException, IllegalStateException, RollbackException, HeuristicMixedException,
          HeuristicRollbackException, SystemException {
    log.info("userProfilePhotoSave called, doing user-profile-photo specific persistence");

    // remove ContentItem from old media content; we get exceptions later on otherwise
    if (currentUser.getProfilePhoto() == null) {
      currentUser.setProfilePhoto(profilePhoto);
    }
    UserService us = (UserService) Component.getInstance("userService");
    //    	us.saveUser(currentUser);
    log.info("profilePhotoId:", profilePhoto.getId());

    currentUserFactory.forceRefresh();
  }
Exemplo n.º 13
0
  //	@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());
  }
Exemplo n.º 14
0
 private String getCIUri(ContentItem ci) {
   return ((KiWiUriResource) ci.getResource()).getUri();
 }
Exemplo n.º 15
0
  @Create
  public void begin() {
    log.info("setting currentContentItem to the active users profile");

    //		currentUser = entityManager.merge(currentUser);
    currentContentItemFactory.setCurrentItemId(currentUser.getContentItem().getId());
    log.info(
        "currentContentItem id set to #0, title: #1",
        currentUser.getContentItem().getId(),
        currentUser.getContentItem().getTitle());
    currentContentItemFactory.refresh();
    Conversation.instance().setDescription("myProfile: " + currentUser.getContentItem().getTitle());

    if (profilePhoto == null) {
      profilePhoto = currentUser.getProfilePhoto();
    }

    if (profilePhoto == null) {
      profilePhoto = contentItemService.createContentItem();
      log.info("creating new contentItem for profilePhoto with the id #0", profilePhoto.getId());
    }

    KiWiProfileFacade currentProfile = profileService.getProfile(currentUser);

    firstName = currentProfile.getFirstName();
    lastName = currentProfile.getLastName();
    gender = currentProfile.getGender();
    birthday = currentProfile.getBirthday();
    email = currentProfile.getEmail();
    phone = currentProfile.getPhone();
    mobile = currentProfile.getMobile();
    street = currentProfile.getStreet();

    if (currentProfile.getCity() != null) {
      if (currentProfile.getCity().getCountry() != null) {
        cityCountry = currentProfile.getCity().getCountry().getISOCode();
      }
      cityPostalCode = currentProfile.getCity().getPostalCode();
      cityName = currentProfile.getCity().getName();
    }

    facebookAccount = currentProfile.getFacebookAccount();
    twitterAccount = currentProfile.getTwitterAccount();
    skypeAccount = currentProfile.getSkype();

    // TODO: should be clickable!
    interests = "";
    for (ContentItem i : currentProfile.getInterests()) {
      interests += i.getTitle() + ", ";
    }

    latitude = currentProfile.getLatitude();
    longitude = currentProfile.getLongitude();

    if (currentProfile.getDelegate().getTextContent() != null) {
      description = currentProfile.getDelegate().getTextContent().getPlainString();
    }
    //		description    = renderingPipeline.renderEditor(currentProfile.getDelegate(), currentUser);

    specificBehavior();
  }