Example #1
0
  /**
   * central place where a target should be loaded
   *
   * @param prov
   * @param targetType
   * @param targetBy
   * @param target
   * @return
   * @throws ServiceException
   */
  static Entry lookupTarget(
      Provisioning prov, TargetType targetType, TargetBy targetBy, String target, boolean mustFind)
      throws ServiceException {
    Entry targetEntry = null;

    switch (targetType) {
      case account:
        targetEntry = prov.get(AccountBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_ACCOUNT(target);
        break;
      case calresource:
        targetEntry = prov.get(CalendarResourceBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_CALENDAR_RESOURCE(target);
        break;
      case dl:
        targetEntry = prov.getAclGroup(DistributionListBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(target);
        break;
      case domain:
        targetEntry = prov.get(DomainBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_DOMAIN(target);
        break;
      case cos:
        targetEntry = prov.get(CosBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_COS(target);
        break;
      case server:
        targetEntry = prov.get(ServerBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_SERVER(target);
        break;
      case xmppcomponent:
        targetEntry = prov.get(XMPPComponentBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(target);
        break;
      case zimlet:
        ZimletBy zimletBy = ZimletBy.fromString(targetBy.name());
        if (zimletBy != ZimletBy.name)
          throw ServiceException.INVALID_REQUEST("zimlet must be by name", null);
        targetEntry = prov.getZimlet(target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_ZIMLET(target);
        break;
      case config:
        targetEntry = prov.getConfig();
        break;
      case global:
        targetEntry = prov.getGlobalGrant();
        break;
      default:
        ServiceException.INVALID_REQUEST(
            "invallid target type for lookupTarget:" + targetType.toString(), null);
    }

    return targetEntry;
  }