示例#1
0
 public static String ResourceNameServices(Spec spec, String uiname) {
   try {
     Record test = spec.getRecordByWebUrl(uiname);
     return test.getAuthorizationType();
   } catch (Exception e) {
     return uiname;
   }
 }
示例#2
0
 /**
  * CSPACE-2894 make permission names match the UI names when the app sends the data to the UI
  *
  * @param spec
  * @param servicename
  * @return
  */
 public static String ResourceNameUI(Spec spec, String servicename) {
   try {
     Record test = null;
     // can we do a simple match
     if (spec.hasRecord(servicename)) {
       test = spec.getRecord(servicename);
     } else if (spec.hasRecordByServicesUrl(servicename)) {
       test = spec.getRecordByServicesUrl(servicename);
     } else {
       // else loop thr the records and see if we can do an auth match
       for (Record r : spec.getAllRecords()) {
         if (r.isAuthorizationType(servicename)) {
           test = r;
         }
       }
     }
     return test.getWebURL();
   } catch (Exception e) {
     return servicename;
   }
 }
示例#3
0
 public static String getPermissionView(Spec spec, String servicename) {
   try {
     Record test = null;
     // can we do a simple match
     if (spec.hasRecordByServicesUrl(servicename)) {
       test = spec.getRecordByServicesUrl(servicename);
     } else {
       // else loop thr the records and see if we can do an auth match
       for (Record r : spec.getAllRecords()) {
         if (r.isAuthorizationType(servicename)) {
           test = r;
         }
       }
     }
     if (test.getAuthorizationView()) {
       return "show";
     }
     return "none";
   } catch (Exception e) {
     // do not display as we don't know what this is
     return "none";
   }
 }
示例#4
0
  private void termlist(CSPRequestCache cache, Storage storage, UIRequest request, String path)
      throws UIException {
    try {
      // {tenant}/{tenantname}/{recordType}/termList/{termListType}
      // needs to be {tenant}/{tenantname}/{recordType}/termList/{fieldname}
      // as blanks etc are on a field basis not a vocab basis
      String[] bits = path.split("/");
      Record vb = this.spec.getRecord("vocab");
      Field f = (Field) r.getFieldTopLevel(bits[0]);
      if (f == null) {
        f = (Field) r.getFieldFullList(bits[0]);
      }
      // If the field isn't in this record, look for it in subrecords (e.g. contacts).
      if (f == null) {
        FieldSet[] subRecordFields = r.getAllSubRecords("GET");

        for (int i = 0; i < subRecordFields.length; i++) {
          FieldSet subRecordField = subRecordFields[i];
          Group group = (Group) subRecordField;

          if (group.usesRecord()) {
            Record subRecord = group.usesRecordId();
            f = (Field) subRecord.getFieldTopLevel(bits[0]);

            if (f == null) {
              f = (Field) subRecord.getFieldFullList(bits[0]);
            }

            if (f != null) {
              break;
            }
          }
        }
      }
      JSONArray result = new JSONArray();
      for (Instance ins : f.getAllAutocompleteInstances()) {
        JSONArray getallnames = ctl.get(storage, ins.getTitleRef(), vb);
        for (int i = 0; i < getallnames.length(); i++) {
          result.put(getallnames.get(i));
        }
      }
      JSONObject out = generateENUMField(storage, f, result, false);
      request.sendJSONResponse(out);
      int cacheMaxAgeSeconds = spec.getAdminData().getTermListCacheAge();
      if (cacheMaxAgeSeconds > 0) {
        request.setCacheMaxAgeSeconds(cacheMaxAgeSeconds);
      }
    } catch (JSONException e) {
      throw new UIException("JSONException during autocompletion", e);
    }
  }
 public void configure(WebUI ui, Spec spec) {
   for (Record r : spec.getAllRecords()) {
     type_to_url.put(r.getID(), r.getWebURL());
   }
 }
  private void search_or_list_vocab(
      JSONObject out,
      Record rd,
      Instance n,
      Storage storage,
      JSONObject restriction,
      String resultstring,
      JSONObject temp)
      throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException,
          UIException {

    JSONObject data = storage.getPathsJSON(rd.getID() + "/" + n.getTitleRef(), restriction);

    String[] paths = (String[]) data.get("listItems");
    JSONObject pagination = new JSONObject();
    if (data.has("pagination")) {
      pagination = data.getJSONObject("pagination");
      pagination.put("numInstances", "1");
    }

    JSONArray members = new JSONArray();
    /* Get a view of each */
    if (temp.has(resultstring)) {
      members = temp.getJSONArray(resultstring);
    }
    for (String result : paths) {

      if (temp.has(resultstring)) {
        temp.getJSONArray(resultstring)
            .put(generateMiniRecord(storage, rd.getID(), n.getTitleRef(), result));
        members = temp.getJSONArray(resultstring);
      } else {
        members.put(generateMiniRecord(storage, rd.getID(), n.getTitleRef(), result));
      }
    }

    out.put(resultstring, members);

    if (pagination != null) {
      if (temp.has("pagination")) {
        JSONObject pag2 = temp.getJSONObject("pagination");
        String itemsInPage = pag2.getString("itemsInPage");
        String pagSize = pag2.getString("pageSize");
        String totalItems = pag2.getString("totalItems");
        String numInstances = pag2.getString("numInstances");

        String itemsInPage1 = pagination.getString("itemsInPage");
        String pagSize1 = pagination.getString("pageSize");
        String totalItems1 = pagination.getString("totalItems");
        Integer numInstances1 = Integer.parseInt(numInstances);
        int iip = Integer.parseInt(itemsInPage) + Integer.parseInt(itemsInPage1);
        int ps = Integer.parseInt(pagSize) + Integer.parseInt(pagSize1);
        int ti = Integer.parseInt(totalItems) + Integer.parseInt(totalItems1);

        pagination.put("itemsInPage", Integer.toString(iip));
        pagination.put("pageSize", Integer.toString(ps));
        pagination.put("totalItems", Integer.toString(ti));
        pagination.put("numInstances", Integer.toString(numInstances1++));
      }
      out.put("pagination", pagination);
    }
    log.debug(restriction.toString());
  }