Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.ILabel


        if (oldIdValue != null && oldIdValue instanceof Long)
          mapOldIdToImportedLabel.put((Long) oldIdValue, importedLabel);
      }

      for (ILabel importedLabel : labels) {
        ILabel existingLabel = mapExistingLabelToName.get(importedLabel.getName());

        /* Update Existing */
        if (existingLabel != null) {
          existingLabel.setColor(importedLabel.getColor());
          if (existingLabel.getOrder() != importedLabel.getOrder())
            fixLabelOrder = true;
          existingLabel.setOrder(importedLabel.getOrder());
          DynamicDAO.save(existingLabel);
        }

        /* Save as New */
        else {
          importedLabel.removeProperty(ITypeImporter.ID_KEY);
          DynamicDAO.save(importedLabel);
          fixLabelOrder = true;
        }
      }

      /* Fix Order to be a sequence again */
      if (fixLabelOrder && !existingLabels.isEmpty()) {
        Set<ILabel> sortedLabels = CoreUtils.loadSortedLabels();
        int index = 0;
        for (Iterator<?> iterator = sortedLabels.iterator(); iterator.hasNext();) {
          ILabel label = (ILabel) iterator.next();
          label.setOrder(index);
          index++;
        }

        DynamicDAO.saveAll(sortedLabels);
      }
    }

    /* Import Filters */
    if (filters != null && !filters.isEmpty()) {
      int existingFiltersCount = DynamicDAO.loadAll(ISearchFilter.class).size();

      /* Fix locations in Searches if required */
      List<ISearch> locationConditionSearches = getLocationConditionSearchesFromFilters(filters);
      if (!locationConditionSearches.isEmpty())
        updateLocationConditions(mapOldIdToFolderChild, locationConditionSearches);

      /* Fix locations in Actions if required */
      for (ISearchFilter filter : filters) {
        List<IFilterAction> actions = filter.getActions();
        for (IFilterAction action : actions) {
          if (MoveNewsAction.ID.equals(action.getActionId()) || CopyNewsAction.ID.equals(action.getActionId())) {
            Object data = action.getData();
            if (data != null && data instanceof Long[]) {
              Long[] oldBinLocations = (Long[]) data;
              List<Long> newBinLocations = new ArrayList<Long>(oldBinLocations.length);

              for (int i = 0; i < oldBinLocations.length; i++) {
                Long oldLocation = oldBinLocations[i];
                if (mapOldIdToFolderChild.containsKey(oldLocation)) {
                  IFolderChild location = mapOldIdToFolderChild.get(oldLocation);
                  newBinLocations.add(location.getId());
                }
              }

              action.setData(newBinLocations.toArray(new Long[newBinLocations.size()]));
            }
          }
        }
      }

      /* Fix labels in Actions if required */
      for (ISearchFilter filter : filters) {
        List<IFilterAction> actions = filter.getActions();
        for (IFilterAction action : actions) {
          if (LabelNewsAction.ID.equals(action.getActionId())) {
            Object data = action.getData();
            if (data != null && data instanceof Long) {
              ILabel label = mapOldIdToImportedLabel.get(data);
              if (label != null) {
                String name = label.getName();
                ILabel existingLabel = mapExistingLabelToName.get(name);
                if (existingLabel != null)
                  action.setData(existingLabel.getId());
                else
                  action.setData(label.getId());
              }
            }
          }
View Full Code Here


  /**
   * @throws Exception
   */
  @Test
  public void testGetEntitiesFromSelection() throws Exception {
    ILabel label1 = fFactory.createLabel(null, "Label 1");
    ILabel label2 = fFactory.createLabel(null, "Label 2");
    ILabel label3 = fFactory.createLabel(null, "Label 3");

    EntityGroup group = new EntityGroup(1, "Group");
    new EntityGroupItem(group, label2);
    new EntityGroupItem(group, label3);

View Full Code Here

  /**
   * @throws Exception
   */
  @Test
  public void testGetEntitiesFromSelectionWithClass() throws Exception {
    ILabel label1 = fFactory.createLabel(null, "Label 1");
    ILabel label2 = fFactory.createLabel(null, "Label 2");
    ILabel label3 = fFactory.createLabel(null, "Label 3");
    IFeed feed1 = fFactory.createFeed(null, new URI("http://www.news.com"));

    EntityGroup group = new EntityGroup(1, "Group");
    new EntityGroupItem(group, label2);
    new EntityGroupItem(group, label3);
View Full Code Here

  /**
   * @throws Exception
   */
  @Test
  public void testIsLabelChangeSingle() throws Exception {
    ILabel label1 = new Label(null, "Label1");
    ILabel label2 = new Label(null, "Label2");

    IFeed feed = new Feed(new URI("http://www.link.com"));
    INews news1 = new News(null, feed, new Date());
    news1.addLabel(label1);

View Full Code Here

  /**
   * @throws Exception
   */
  @Test
  public void testIsLabelChangeMulti() throws Exception {
    ILabel label1 = new Label(null, "Label1");
    ILabel label2 = new Label(null, "Label2");
    ILabel label3 = new Label(null, "Label3");

    IFeed feed = new Feed(new URI("http://www.link.com"));
    INews news1 = new News(null, feed, new Date());
    news1.addLabel(label1);
    news1.addLabel(label3);
View Full Code Here

  /**
   * @throws Exception
   */
  @Test
  public void testGetLabelsForAll() throws Exception {
    ILabel label1 = DynamicDAO.save(fFactory.createLabel(null, "Foo"));
    ILabel label2 = DynamicDAO.save(fFactory.createLabel(null, "Bar"));

    IFeed feed = fFactory.createFeed(null, new URI("feed"));
    INews news1 = fFactory.createNews(null, feed, new Date());
    INews news2 = fFactory.createNews(null, feed, new Date());
    INews news3 = fFactory.createNews(null, feed, new Date());
View Full Code Here

    String id = labelElement.getAttributeValue(Attributes.ID.get());
    String name = labelElement.getAttributeValue(Attributes.NAME.get());
    String order = labelElement.getAttributeValue(Attributes.ORDER.get());
    String color = labelElement.getAttributeValue(Attributes.COLOR.get());

    ILabel label = Owl.getModelFactory().createLabel(null, name);
    label.setColor(color);
    label.setOrder(Integer.parseInt(order));
    label.setProperty(ID_KEY, Long.valueOf(id));

    importedEntities.add(label);
  }
View Full Code Here

      FolderEvent eventTemplate = (FolderEvent) template;
      IFolder oldParent = eventTemplate == null ? null : eventTemplate.getOldParent();
      modelEvent = new FolderEvent(folder, oldParent, root);
    }
    else if (entity instanceof ILabel) {
      ILabel label = (ILabel) entity;
      LabelEvent eventTemplate = (LabelEvent) template;
      ILabel oldLabel = eventTemplate == null ? null : eventTemplate.getOldLabel();
      modelEvent = new LabelEvent(oldLabel, label, root);
    }
    else if (entity instanceof ISearchCondition) {
      ISearchCondition searchCond = (ISearchCondition) entity;
      modelEvent = new SearchConditionEvent(searchCond, root);
View Full Code Here

        /* Re-Index all News when a containing Label updates */
        ISearchField searchField = Owl.getModelFactory().createSearchField(INews.LABEL, INews.class.getName());

        Set<Long> newsIndexed = new HashSet<Long>();
        for (LabelEvent labelEvent : events) {
          ILabel oldLabel = labelEvent.getOldLabel();
          ILabel updatedLabel = labelEvent.getEntity();
          if (oldLabel != null && !oldLabel.getName().equals(updatedLabel.getName())) {
            ISearchCondition searchCondition = Owl.getModelFactory().createSearchCondition(searchField, SearchSpecifier.IS, oldLabel.getName());
            List<SearchHit<NewsReference>> hits = Owl.getPersistenceService().getModelSearch().searchNews(Collections.singletonList(searchCondition), true);

            List<INews> newsList = new ArrayList<INews>(hits.size());
            for (SearchHit<NewsReference> hit : hits) {
View Full Code Here

    /* Assign New Labels */
    if (labelsValueSplit.length > 0) {

      /* For each typed Label */
      for (String labelValue : labelsValueSplit) {
        ILabel label = null;
        labelValue = labelValue.trim();
        if (labelValue.length() == 0)
          continue;

        /* Check if Label exists */
        for (ILabel existingLabel : fExistingLabels) {
          if (existingLabel.getName().toLowerCase().equals(labelValue.toLowerCase())) {
            label = existingLabel;
            break;
          }
        }

        /* Create new Label if necessary */
        if (label == null) {
          ILabel newLabel = Owl.getModelFactory().createLabel(null, labelValue);
          newLabel.setColor(OwlUI.toString(new RGB(0, 0, 0)));
          newLabel.setOrder(fExistingLabels.size());
          DynamicDAO.save(newLabel);
          fExistingLabels.add(newLabel);
          label = newLabel;
        }

View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.ILabel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.