Package com.google.livingstories.server.dataservices.entities

Examples of com.google.livingstories.server.dataservices.entities.BaseContentEntity$LocationEntity


  @Override
  public synchronized BaseContentItem save(BaseContentItem baseContent) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Transaction tx = null;
    BaseContentEntity contentEntity;

    try {
      if (baseContent.getId() == null) {
        contentEntity = BaseContentEntity.fromClientObject(baseContent);
      } else {
        contentEntity = pm.getObjectById(BaseContentEntity.class, baseContent.getId());
        contentEntity.copyFields(baseContent);
      }
      tx = pm.currentTransaction();
      tx.begin();
      pm.makePersistent(contentEntity);
      tx.commit();
      return contentEntity.toClientObject();
    finally {
      if (tx != null && tx.isActive()) {
        tx.rollback();
      }
      pm.close();
View Full Code Here


  @Override
  public synchronized void delete(final Long id) {
    PersistenceManager pm = PMF.get().getPersistenceManager();

    try {
      BaseContentEntity contentEntity = pm.getObjectById(BaseContentEntity.class, id);
      // First remove the object being deleted from the linked fields of other objects
      updateContentEntityReferencesHelper(pm, "linkedContentEntityIds", id,
          new Function<BaseContentEntity, Void>() {
            public Void apply(BaseContentEntity contentEntity) {
              contentEntity.removeLinkedContentEntityId(id);
              return null;
            }
          });
      // If deleting a player, remove it from contributorIds of other objects that may contain it
      if (contentEntity.getContentItemType() == ContentItemType.PLAYER) {
        updateContentEntityReferencesHelper(pm, "contributorIds", id,
            new Function<BaseContentEntity, Void>() {
              public Void apply(BaseContentEntity contentEntity) {
                contentEntity.removeContributorId(id);
                return null;
              }
            });
      }
      pm.deletePersistent(contentEntity);
View Full Code Here

      runAutoLink = false;
    }
   
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Transaction tx = null;
    BaseContentEntity contentEntity;
    PublishState oldPublishState = null;
   
    Set<Long> newLinkedContentItemSuggestions = null;
   
    try {
      if (contentItem.getId() != null) {
        contentEntity = pm.getObjectById(BaseContentEntity.class, contentItem.getId());
        oldPublishState = contentEntity.getPublishState();
        contentEntity.copyFields(contentItem);
      } else {
        contentEntity = BaseContentEntity.fromClientObject(contentItem);
      }
     
      if (runAutoLink) {
        newLinkedContentItemSuggestions =
            AutoLinkEntitiesInContent.createLinks(contentEntity, playerContentItems, concepts);
      }

      tx = pm.currentTransaction();
      tx.begin();
      pm.makePersistent(contentEntity);
      tx.commit();
     
      // If this was an event or a narrative and had a linked narrative, then the 'standalone'
      // field on the narrative content item needs to be updated to 'false'.
      // Note: this doesn't handle the case of unlinking a previously linked narrative content item.
      // That would require checking the linked content items of every single other event
      // content item to make sure it's not linked to from anywhere else, which would be an
      // expensive operation.
      Set<Long> linkedContentEntityIds = contentEntity.getLinkedContentEntityIds();
      ContentItemType contentItemType = contentEntity.getContentItemType();
      if ((contentItemType == ContentItemType.EVENT || contentItemType == ContentItemType.NARRATIVE)
          && !linkedContentEntityIds.isEmpty()) {
        List<Object> oids = new ArrayList<Object>(linkedContentEntityIds.size());
        for (Long id : linkedContentEntityIds) {
          oids.add(pm.newObjectIdInstance(BaseContentEntity.class, id));
        }

        @SuppressWarnings("unchecked")
        Collection<BaseContentEntity> linkedContentEntities = pm.getObjectsById(oids);
        for (BaseContentEntity linkedContentEntity : linkedContentEntities) {
          if (linkedContentEntity.getContentItemType() == ContentItemType.NARRATIVE) {
            linkedContentEntity.setIsStandalone(false);
          }
        }
      }

      // TODO: may also want to invalidate linked content items if they changed
      // and aren't from the same living story.
      invalidateCache(contentItem.getLivingStoryId());
    } finally {
      if (tx != null && tx.isActive()) {
        tx.rollback();
      }
      pm.close();
    }
   
    // Send email alerts if an event content item was changed from 'Draft' to 'Published'
    if (contentEntity.getContentItemType() == ContentItemType.EVENT
        && contentEntity.getPublishState() == PublishState.PUBLISHED
        && oldPublishState != null && oldPublishState == PublishState.DRAFT) {
      sendEmailAlerts((EventContentItem)contentItem);
    }

    // We pass suggested new linked content items back to the client by adding their ids to the
    // client object before returning it. It's the client's responsibility to check the linked
    // content item ids it passed in with those that came back, and to present appropriate
    // UI for processing the suggestions. Note that we shouldn't add the suggestions directly
    // to contentEntity! This will persist them to the datastore prematurely.
    BaseContentItem ret = contentEntity.toClientObject();
   
    if (newLinkedContentItemSuggestions != null) {
      ret.addAllLinkedContentItemIds(newLinkedContentItemSuggestions);
    }
   
View Full Code Here

  @Override
  public synchronized void deleteContentItem(final Long id) {
    PersistenceManager pm = PMF.get().getPersistenceManager();

    try {
      BaseContentEntity contentEntity = pm.getObjectById(BaseContentEntity.class, id);

      updateContentEntityReferencesHelper(pm, "linkedContentEntityIds", id,
          new Function<BaseContentEntity, Void>() {
            public Void apply(BaseContentEntity contentEntity) {
              contentEntity.removeLinkedContentEntityId(id); return null;
            }
          });

      // If deleting a contributor as well, update relevant contributor ids too.
      if (contentEntity.getContentItemType() == ContentItemType.PLAYER) {
        updateContentEntityReferencesHelper(pm, "contributorIds", id,
            new Function<BaseContentEntity, Void>() {
              public Void apply(BaseContentEntity contentEntity) {
                contentEntity.removeContributorId(id); return null;
              }
            });
      }
     
      invalidateCache(contentEntity.getLivingStoryId());
      pm.deletePersistent(contentEntity);
    } finally {
      pm.close();
    }
  }
View Full Code Here

      if (iter == null) {
        iter = contentMap.values().iterator();
      }
      // Map all the ids in the BaseContentEntity objects to the new ones
      while (iter.hasNext()) {
        BaseContentEntity contentEntity = iter.next();
        // Living Story ids
        if (contentEntity.getLivingStoryId() != null) {
          LivingStoryEntity livingStory =
              livingStoryMap.get(contentEntity.getLivingStoryId().toString());
          if (livingStory != null) {
            contentEntity.setLivingStoryId(livingStory.getId());
          }
        }
       
        // Theme ids
        Set<Long> themeIds = Sets.newHashSet();
        for (Long themeId : contentEntity.getThemeIds()) {
          ThemeEntity theme = themeMap.get(themeId.toString());
          if (theme != null) {
            themeIds.add(theme.getId());
          }
        }
        contentEntity.setThemeIds(themeIds);
       
        // Contributor ids
        Set<Long> contributorIds = Sets.newHashSet();
        for (Long contributorId : contentEntity.getContributorIds()) {
          BaseContentEntity user = contentMap.get(contributorId.toString());
          if (user != null) {
            contributorIds.add(user.getId());
          }
        }
        contentEntity.setContributorIds(contributorIds);
       
        // Linked content entity ids
        Set<Long> linkedContentEntityIds = Sets.newHashSet();
        for (Long linkedContentEntityId : contentEntity.getLinkedContentEntityIds()) {
          BaseContentEntity linkedContentEntity = contentMap.get(linkedContentEntityId.toString());
          if (linkedContentEntity != null) {
            linkedContentEntityIds.add(linkedContentEntity.getId());
          }
        }
        contentEntity.setLinkedContentEntityIds(linkedContentEntityIds);
       
        // Photo content entity id
        if (contentEntity.getContentItemType() == ContentItemType.PLAYER
            && contentEntity.getPhotoContentEntityId() != null) {
          BaseContentEntity photoContentEntity =
              contentMap.get(contentEntity.getPhotoContentEntityId().toString());
          if (photoContentEntity != null) {
            contentEntity.setPhotoContentEntityId(photoContentEntity.getId());
          } else {
            contentEntity.setPhotoContentEntityId(null);
          }
        }
       
        // Parent player content entity id
        if (contentEntity.getContentItemType() == ContentItemType.PLAYER
            && contentEntity.getParentPlayerContentEntityId() != null) {
          BaseContentEntity playerParentEntity =
              contentMap.get(contentEntity.getParentPlayerContentEntityId().toString());
          if (playerParentEntity == null) {
            contentEntity.setParentPlayerContentEntityId(null);
          } else {
            contentEntity.setParentPlayerContentEntityId(playerParentEntity.getId());
          }
        }
       
        if (timeout()) {
          return true;
View Full Code Here

      if (iter == null) {
        iter = contentMap.values().iterator();
      }
      while (iter.hasNext()) {
        BaseContentEntity contentEntity = iter.next();
        contentEntity.setContent(matchAll(contentEntity.getContent()));
        if (contentEntity.getContentItemType() == ContentItemType.ASSET) {
          contentEntity.setCaption(matchAll(contentEntity.getCaption()));
        } else if (contentEntity.getContentItemType() == ContentItemType.EVENT) {
          contentEntity.setEventUpdate(matchAll(contentEntity.getEventUpdate()));
          contentEntity.setEventSummary(matchAll(contentEntity.getEventSummary()));
        }
        if (timeout()) {
          return true;
        }
      }
View Full Code Here

TOP

Related Classes of com.google.livingstories.server.dataservices.entities.BaseContentEntity$LocationEntity

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.