Example #1
0
  /**
   * List an organization's allocation of a system entitlement.
   *
   * @param sessionKey User's session key.
   * @param label System entitlement label.
   * @param includeUnentitled If true, the result will include both organizations that have the
   *     entitlement as well as those that do not; otherwise, the result will only include
   *     organizations that have the entitlement.
   * @return a list of Maps having the system entitlements info.
   * @since 10.4
   * @xmlrpc.doc List each organization's allocation of a system entitlement.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("string", "label")
   * @xmlrpc.param #param_desc("boolean", "includeUnentitled", "If true, the result will include
   *     both organizations that have the entitlement as well as those that do not; otherwise, the
   *     result will only include organizations that have the entitlement.")
   * @xmlrpc.returntype #array() #struct("entitlement usage") #prop("int", "org_id") #prop("string",
   *     "org_name") #prop("int", "allocated") #prop("int", "unallocated") #prop("int", "used")
   *     #prop("int", "free") #struct_end() #array_end()
   */
  public List<Map> listSystemEntitlements(
      String sessionKey, String label, Boolean includeUnentitled) {

    getSatAdmin(sessionKey);
    verifyEntitlementExists(label);

    DataList<Map> result = null;
    if (includeUnentitled) {
      result = OrgManager.allOrgsSingleEntitlementWithEmptyOrgs(label);
    } else {
      result = OrgManager.allOrgsSingleEntitlement(label);
    }

    List<Map> details = new LinkedList<Map>();
    for (Map row : result) {
      Map<String, Object> map = new HashMap<String, Object>();
      Org org = OrgFactory.lookupById((Long) row.get("orgid"));
      map.put(ORG_ID_KEY, new Integer(org.getId().intValue()));
      map.put(ORG_NAME_KEY, org.getName());
      map.put(ALLOCATED_KEY, ((Long) row.get("total")).intValue());
      map.put(USED_KEY, row.get("usage"));
      long free = (Long) row.get("total") - (Long) row.get("usage");
      map.put(FREE_KEY, free);
      long unallocated = (Long) row.get("upper") - (Long) row.get("total");
      map.put(UN_ALLOCATED_KEY, unallocated);
      details.add(map);
    }
    return details;
  }
Example #2
0
 /** {@inheritDoc} */
 @Override
 public boolean equals(Object other) {
   if (!(other instanceof Org)) {
     return false;
   }
   Org otherOrg = (Org) other;
   return new EqualsBuilder().append(getName(), otherOrg.getName()).isEquals();
 }
 public void testCommitOrg() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   String changedName = "OrgFactoryTest testCommitOrg " + TestUtils.randomString();
   org1.setName(changedName);
   org1 = OrgFactory.save(org1);
   Long id = org1.getId();
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(id);
   assertEquals(changedName, org2.getName());
 }
Example #4
0
 /**
  * @param sessionKey Caller's session key.
  * @param orgId the orgId of the organization to set name on
  * @param name the new name for the org.
  * @return the updated org.
  * @xmlrpc.doc Updates the name of an organization
  * @xmlrpc.param #param("string", "sessionKey")
  * @xmlrpc.param #param("int", "orgId")
  * @xmlrpc.param #param_desc("string", "name", "Organization name. Must meet same criteria as in
  *     the web UI.")
  * @xmlrpc.returntype $OrgDtoSerializer
  */
 public OrgDto updateName(String sessionKey, Integer orgId, String name) {
   getSatAdmin(sessionKey);
   Org org = verifyOrgExists(orgId);
   if (!org.getName().equals(name)) {
     try {
       OrgManager.checkOrgName(name);
       org.setName(name);
     } catch (ValidatorException ve) {
       throw new ValidationException(ve.getMessage());
     }
   }
   return OrgManager.toDetailsDto(org);
 }
Example #5
0
  /**
   * List the organizations associated with the given channel that may be trusted.
   *
   * @param loggedInUser The current user
   * @param channelLabel The label for the channel
   * @return List of map entries indicating the orgs available and if access is enabled.
   * @throws FaultException A FaultException is thrown if: - The sessionKey is invalid - The
   *     channelLabel is invalid - The user doesn't have channel admin permissions
   * @xmlrpc.doc List the organizations associated with the given channel that may be trusted.
   * @xmlrpc.param #session_key()
   * @xmlrpc.param #param_desc("string", "channelLabel", "label of the channel")
   * @xmlrpc.returntype #array() #struct("org") #prop("int", "org_id") #prop("string", "org_name")
   *     #prop("boolean", "access_enabled") #struct_end() #array_end()
   */
  public List list(User loggedInUser, String channelLabel) throws FaultException {

    Channel channel = lookupChannelByLabel(loggedInUser, channelLabel);
    verifyChannelAdmin(loggedInUser, channel);

    if (!loggedInUser.getOrg().equals(channel.getOrg())) {
      // users are not allowed to access properties for a channel that is in a
      // different org
      throw new NotPermittedByOrgException(
          loggedInUser.getOrg().getId().toString(),
          channel.getLabel(),
          channel.getOrg().getId().toString());
    }

    // retrieve the orgs available to be "trusted" for this channel
    List<OrgChannelDto> orgs = OrgManager.orgChannelTrusts(channel.getId(), loggedInUser.getOrg());
    // retrieve the orgs that are trusted for this channel
    Set<Org> trustedOrgs = channel.getTrustedOrgs();

    // populate a result that includes all orgs that could be trusted with a boolean
    // that indicates if the orgs is indeed trusted.
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    for (OrgChannelDto orgDto : orgs) {
      Org org = OrgFactory.lookupById(orgDto.getId());

      if (org != null) {
        Map<String, Object> entry = new HashMap<String, Object>();

        entry.put("org_id", org.getId().intValue());
        entry.put("org_name", org.getName());
        if (trustedOrgs.contains(org)) {
          entry.put("access_enabled", Boolean.TRUE);
        } else {
          entry.put("access_enabled", Boolean.FALSE);
        }
        result.add(entry);
      }
    }
    return result;
  }
 public void testCreateOrg() throws Exception {
   Org org1 = createTestOrg();
   Org org2 = OrgFactory.lookupById(org1.getId());
   assertEquals(org2.getName(), org1.getName());
   assertNotNull(org2.getOwnedChannels());
 }