Examples of UIModulePojoApiMap


Examples of com.ikanow.infinit.e.data_model.api.gui.UIModulePojoApiMap

      }//TESTED
     
      // Now add community code, requires
      DBCursor dbc = DbManager.getSocial().getUIModules().find(query);
      List<UIModulePojo> mps = UIModulePojo.listFromDb(dbc, UIModulePojo.listType());
      rp.setData(mps, new UIModulePojoApiMap(bAdmin?null:memberOf));
      rp.setResponse(new ResponseObject("Get Modules",true,"modules returned successfully"));
    }
    catch (Exception ex)
    {
      rp.setResponse(new ResponseObject("Get Modules",false,"error returning modules"));
View Full Code Here

Examples of com.ikanow.infinit.e.data_model.api.gui.UIModulePojoApiMap

      FavoriteUIModulePojo moduleQuery = new FavoriteUIModulePojo();
      moduleQuery.setProfileId(new ObjectId(userIdStr));
      DBObject dbo = DbManager.getSocial().getUIFavoriteModules().findOne(moduleQuery.toDb());     
      HashSet<ObjectId> memberOf = SocialUtils.getUserCommunities(userIdStr);
      List<UIModulePojo> mods = getFullModule(FavoriteUIModulePojo.fromDb(dbo,FavoriteUIModulePojo.class).getQuickModules(), memberOf, bAdmin);
      rp.setData(mods, new UIModulePojoApiMap(bAdmin?null:memberOf));
      rp.setResponse(new ResponseObject("Get User Modules",true,"users modules returned successfully"));
    }
    catch (Exception ex)
    {
      rp.setResponse(new ResponseObject("Get User Modules",false,"error returning user modules"));
View Full Code Here

Examples of com.ikanow.infinit.e.data_model.api.gui.UIModulePojoApiMap

        BasicDBObject query_nosec =  new BasicDBObject("communityIds", new BasicDBObject("$exists", false));
        query.put("$or", Arrays.asList(query_communities, query_nosec));
      }//TESTED 
      DBCursor dbc = DbManager.getSocial().getUIModules().find(query);
      mods = UIModulePojo.listFromDb(dbc, UIModulePojo.listType());
      rp.setData(mods, new UIModulePojoApiMap(bAdmin?null:memberOf));
      rp.setResponse(new ResponseObject("Search Modules",true,updateItem));
    }
    catch (Exception ex)
    {     
      rp.setResponse(new ResponseObject("Get User Modules",false,"searched modules unsuccessfully for " + updateItem));
View Full Code Here

Examples of com.ikanow.infinit.e.data_model.api.gui.UIModulePojoApiMap

  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();
      rp.setResponse(new ResponseObject("Install Module",false,"Module install error: " + ex.getMessage()));     
    }//TESTED
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.