Examples of UIModulePojo


Examples of com.ikanow.infinit.e.data_model.store.social.gui.UIModulePojo

    List<UIModulePojo> mods = new ArrayList<UIModulePojo>();   
    try
    {
      for ( int i = 0; i < moduleids.size(); i++ //loop through all the ids sent in, and grab the module   
      {
        UIModulePojo moduleQuery = new UIModulePojo();
        moduleQuery.set_id(moduleids.get(i));
        DBObject dbo = DbManager.getSocial().getUIModules().findOne(moduleQuery.toDb());
        if ( dbo != null) {
          UIModulePojo module = UIModulePojo.fromDb(dbo,UIModulePojo.class);
          if (null != module.getCommunityIds()) {
            if (bAdmin) {
              mods.add(module);
            }
            else if (null != memberOf) {
              for (ObjectId communityId: module.getCommunityIds()) {
                if (memberOf.contains(communityId)) {
                  mods.add(module);
                  break;
                }
              }
View Full Code Here

Examples of com.ikanow.infinit.e.data_model.store.social.gui.UIModulePojo

  public ResponsePojo installModule(String moduleJson, String userIdStr)
  {
    ResponsePojo rp = new ResponsePojo();
    try
    {
      UIModulePojo module = ApiManager.mapFromApi(moduleJson, UIModulePojo.class, new UIModulePojoApiMap(null));
        // (allow all communities submitted by the user)
      module.setSwf(""); // (no longer needed)
      module.setApproved(true); // (no mechanism for admin authentication / or of communities)
     
      // Check it's all valid (id can be null
      if ((null == module.getDescription())||(null == module.getImageurl())
          ||(null == module.getUrl())||(null == module.getTitle())||(null == module.getVersion()))
      {
        rp.setResponse(new ResponseObject("Install Module",false,"Missing one of description, image url, url, title, or version"));
        return rp;
      }//TESTED
      else {
        boolean bAdmin = RESTTools.adminLookup(userIdStr);

        if (!bAdmin) { // need to be owner or moderator to add to a community
          if (null == module.getCommunityIds() || module.getCommunityIds().isEmpty()) {
            module.addToCommunityIds(new ObjectId(userIdStr)); // (ie adds to personal community)
          }
          else {
            HashSet<ObjectId> newSet = new HashSet<ObjectId>();
            for (ObjectId communityId: module.getCommunityIds()) {
              if (!SocialUtils.isOwnerOrModerator(communityId.toString(), userIdStr)) {
                rp.setResponse(new ResponseObject("Install Module",false,"Don't have permission to update one or more communities: " + communityId.toString()));
                return rp;
              }
              newSet.add(communityId);
            }
            if (newSet.isEmpty()) {
              newSet.add(new ObjectId(userIdStr)); // (ie adds to personal community)
            }
            module.setCommunityIds(newSet);
          }
        }//TESTED
       
        // Get username from profile id:
        AuthenticationPojo userQuery = new AuthenticationPojo();
        userQuery.setProfileId(new ObjectId(userIdStr));
        BasicDBObject userDbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(userQuery.toDb());
        String userName = userIdStr;
        if (null != userDbo) {
          AuthenticationPojo user =  AuthenticationPojo.fromDb(userDbo, AuthenticationPojo.class);
          userName = user.getUsername();
        }//TESTED
        if (!bAdmin || (null == module.getAuthor())) {
          module.setAuthor(userName);
            // (if module name set and I'm admin then allow it)
        }
       
        if (null == module.get_id()) { // Either new, or no id specified
         
          // Check if it exists (uniquely defined by url + owner)
          UIModulePojo queryModule = new UIModulePojo();
          queryModule.setUrl(module.getUrl());
          queryModule.setAuthor(userName);
          BasicDBObject oldModuleDbo = (BasicDBObject) DbManager.getSocial().getUIModules().findOne(queryModule.toDb());
         
          if (null == oldModuleDbo) { // New module
            module.set_id(new ObjectId());
            module.setCreated(new Date());
            //DEBUG
            //System.out.println("New module: " + module.getUrl());
          }//TESTED
          else { // Overwrite
            UIModulePojo oldModule = UIModulePojo.fromDb(oldModuleDbo, UIModulePojo.class);
            module.set_id(oldModule.get_id());
            //DEBUG
            //System.out.println("Overwrite module: " + module.get_id());
          }//TESTED
          module.setModified(new Date());
        }//TESTED
        else { // Check if it already exists, owner must match if so

          UIModulePojo moduleQuery = new UIModulePojo();
          moduleQuery.set_id(module.get_id());
          BasicDBObject oldModuleDbo = (BasicDBObject) DbManager.getSocial().getUIModules().findOne(moduleQuery.toDb());
          if (null == oldModuleDbo) {
            // Fine, carry on
            //DEBUG
            //System.out.println("Id specified for new module: " + module.get_id());
          }//TESTED
          else {
            UIModulePojo oldModule = UIModulePojo.fromDb(oldModuleDbo, UIModulePojo.class);
            if ((null != oldModule.getAuthor()) && (!userName.equals(oldModule.getAuthor())))
            { // Owner doesn't match
              if (!bAdmin) {
                rp.setResponse(new ResponseObject("Install Module",false,"Permissions error: must be either owner or root"));
                return rp;             
              }
            }//TESTED           
          }
         
          //Set modified
          module.setModified(new Date());
        }
      }
      // Insert or update:
      DbManager.getSocial().getUIModules().save(module.toDb());
     
      UIModulePojo returnVal = new UIModulePojo();
      returnVal.set_id(module.get_id());
      returnVal.setApproved(true);
      rp.setResponse(new ResponseObject("Install Module",true,"module installed/updated successfully"));
      rp.setData(returnVal, new UIModulePojoApiMap(null));
    }
    catch (Exception ex) {
      //ex.printStackTrace();
View Full Code Here

Examples of com.ikanow.infinit.e.data_model.store.social.gui.UIModulePojo

  public ResponsePojo deleteModule(String moduleId, String userIdStr)
  {
    ResponsePojo rp = new ResponsePojo();
    try
    {
      UIModulePojo moduleQuery = new UIModulePojo();
      moduleQuery.set_id(new ObjectId(moduleId));
      BasicDBObject oldModuleDbo = (BasicDBObject) DbManager.getSocial().getUIModules().findOne(moduleQuery.toDb());
      if (null == oldModuleDbo) {
        rp.setResponse(new ResponseObject("Delete Module",false,"Module doesn't exist"));
        return rp;
      }//TESTED
      UIModulePojo oldModule = UIModulePojo.fromDb(oldModuleDbo, UIModulePojo.class);
     
      // Get username from profile id:
      AuthenticationPojo userQuery = new AuthenticationPojo();
      userQuery.setProfileId(new ObjectId(userIdStr));
      BasicDBObject userDbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(userQuery.toDb());       
      String userName = userIdStr;
      if (null != userDbo) {
        AuthenticationPojo user =  AuthenticationPojo.fromDb(userDbo, AuthenticationPojo.class);
        userName = user.getUsername();
      }//TOTEST
     
      String moduleOwner = oldModule.getAuthor();
      if ((null == moduleOwner) || (moduleOwner.equals(userName)) || RESTTools.adminLookup(userIdStr)) {
        DbManager.getSocial().getUIModules().remove(moduleQuery.toDb());
        rp.setResponse(new ResponseObject("Delete Module",true,"module deleted successfully"));
      }//TESTED
      else {
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.