Examples of PersonalShareableContentItem


Examples of com.gadglet.data.PersonalShareableContentItem

   * @throws RequestException
   */
  public boolean delete(GadgletRequestWrapper request, Class<?> className)
      throws RequestException {

    PersonalShareableContentItem item = null;
    PersistenceManager pm = null;

    try {
      pm = PMF.get().getPersistenceManager();
      item = getSingleItemByKeyForAction(pm, request, className);
View Full Code Here

Examples of com.gadglet.data.PersonalShareableContentItem

   */
  public void shareItem(GadgletRequestWrapper request, Class<?> className)
      throws RequestException {

    PersistenceManager pm = PMF.get().getPersistenceManager();
    PersonalShareableContentItem item = (PersonalShareableContentItem) getSingleItemByKeyForAction(
        pm, request, className);

    String shareWith = request.getParameter(ReqParamNames.SHARE_WITH
        .getParamName());
    SharingType sharingType = request.getSharingType();
    SharedItemReff newShare = null;
    boolean shareExists = false;
    int remove = -1;
    List<SharedItemReff> sharings = null;

    // missing shareWith
    if (shareWith == null) {
      pm.close();
      throw new RequestException(ReqErrorTypes.MISSING_ARGUMENT);
    }

    // not owner
    if (!item.getOwnerId().equals(request.getCurrentUserId())) {
      pm.close();
      throw new RequestException(ReqErrorTypes.UNAUTHORIZED_OPERATION);

    }

    // can't change owner settings
    if (item.getOwnerId().equals(shareWith)) {
      pm.close();
      throw new RequestException(ReqErrorTypes.UNAUTHORIZED_OPERATION);

    }

    try {
      sharings = item.getSharedItemReff();
      int index = 0;
      for (SharedItemReff share : sharings) {

        if (share.getSharedWithId().equals(shareWith)
            && !share.getSharingType().equals(SharingType.OWNER)) {
          shareExists = true;

          if (sharingType == null)
            remove = index;
          else
            share.setSharingType(sharingType);
        }

        index++;
      }
      // add
      if (remove > -1)
        item.getSharedItemReff().remove(remove);
      // add new sharing
      if (!shareExists && request.getSharingType() != null
          && !request.getSharingType().equals(SharingType.OWNER)) {
        newShare = new SharedItemReff();

        newShare.setSharedWithId(request
            .getParameter(ReqParamNames.SHARE_WITH.getParamName()));
        newShare.setSharingType(request.getSharingType());
        item.addSharedItemReff(newShare);
      }

      updated(pm, item, request);
    } catch (RequestException e) {
      throw e;
View Full Code Here

Examples of com.gadglet.data.PersonalShareableContentItem

   */
  public PersonalShareableContentItem getSingleItemByKeyForAction(
      PersistenceManager pm, GadgletRequestWrapper request,
      Class<?> className) throws RequestException {

    PersonalShareableContentItem item = null;

    String key = request.getItemKeyField();
    if (key == null)
      throw new RequestException(ReqErrorTypes.ITEM_NOT_FOUND);

    try {

      item = (PersonalShareableContentItem) pm.getObjectById(className,
          key);
      // access all fields before pm is closed to ensure fields are
      // available
      if (item != null && item.getSharedItemReff() != null)
        for (SharedItemReff ref : item.getSharedItemReff())
          ref.getSharingType();

    } catch (Exception e) {
      log.warning(e.getMessage());
      throw new RequestException(ReqErrorTypes.ITEM_NOT_FOUND);
View Full Code Here

Examples of com.gadglet.data.PersonalShareableContentItem

   */
  public PersonalShareableContentItem getSingleItemByKey(
      GadgletRequestWrapper request, Class<?> className)
      throws RequestException {

    PersonalShareableContentItem item = null;

    String key = request.getItemKeyField();
    if (key == null)
      throw new RequestException(ReqErrorTypes.ITEM_NOT_FOUND);

    PersistenceManager pm = PMF.get().getPersistenceManager();

    try {

      item = (PersonalShareableContentItem) pm.getObjectById(className,
          key);

      // access all fields before pm is closed to ensure fields are
      // available
      if (item != null && item.getSharedItemReff() != null)
        for (SharedItemReff ref : item.getSharedItemReff())
          ref.getSharingType();

    } catch (Exception e) {
      log.warning(e.getMessage());
      throw new RequestException(ReqErrorTypes.ITEM_NOT_FOUND);
View Full Code Here

Examples of com.gadglet.data.PersonalShareableContentItem

    SharedItemReff reff = new SharedItemReff(SharingType.OWNER,
        item.getOwnerId());

    item.addSharedItemReff(reff);

    PersonalShareableContentItem savedItem = null;
    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.currentTransaction().begin();
    try {

      savedItem = pm.makePersistent(item);
      pm.currentTransaction().commit();
    } catch (Exception e) {
      log.warning(e.getMessage());
      throw new RequestException(ReqErrorTypes.REQUEST_FAILED);
    } finally {
      if (pm.currentTransaction().isActive())
        pm.currentTransaction().rollback();
      pm.close();
    }

    if (savedItem == null)
      return null;
    else
      return savedItem.getContentItemKey();

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.