示例#1
0
  public static JsonValue removePaths(JsonValue jsonValue, Paths paths, Paths pathsToIgnore) {
    if (paths.matches(pathsToIgnore)) return JsonValue.NULL;

    if (jsonValue.isObject()) {
      paths = new Paths(paths);
      paths.extend("{}");

      if (paths.matches(pathsToIgnore)) return JsonValue.NULL;

      JsonObject jsonObject = new JsonObject();
      for (String name : jsonValue.asObject().names()) {
        Paths currentPaths = new Paths(paths);
        currentPaths.extend(name);
        jsonObject.set(
            name, removePaths(jsonValue.asObject().get(name), currentPaths, pathsToIgnore));
      }
      return jsonObject;
    }
    if (jsonValue.isArray()) {
      Paths currentPaths = new Paths(paths);
      currentPaths.extend("[]");

      if (currentPaths.matches(pathsToIgnore)) return JsonValue.NULL;

      JsonArray jsonArray = new JsonArray();
      for (int index = 0; index < jsonValue.asArray().size(); index++) {
        currentPaths = new Paths(paths);
        currentPaths.extend("[]", "[" + index + "]");

        jsonArray.add(removePaths(jsonValue.asArray().get(index), currentPaths, pathsToIgnore));
      }
      return jsonArray;
    }
    return jsonValue;
  }
 @Override
 protected void parseMember(JsonObject.Member member) {
   super.parseMember(member);
   try {
     JsonValue value = member.getValue();
     String memberName = member.getName();
     if ("roles".equals(memberName)) {
       this.writable =
           value
               .asArray()
               .values()
               .stream()
               .filter(JsonValue::isString)
               .map(JsonValue::asString)
               .anyMatch("write"::equalsIgnoreCase);
     } else if ("link".equals(memberName)) {
       link = new OneDriveSharingLink(value.asObject());
     } else if ("grantedTo".equals(memberName)) {
       grantedTo = new OneDriveIdentitySet(value.asObject());
     } else if ("inheritedFrom".equals(memberName)) {
       JsonObject valueObject = value.asObject();
       String id = valueObject.get("id").asString();
       OneDriveFolder inheritedFromFolder = new OneDriveFolder(getApi(), id);
       inheritedFrom = inheritedFromFolder.new Reference(valueObject);
     } else if ("shareId".equals(memberName)) {
       shareId = value.asString();
     }
   } catch (ParseException e) {
     throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
   }
 }
示例#3
0
 @Override
 public void getContactRequests(boolean fromWebsocket) throws ConnectionException {
   JsonArray array =
       Endpoints.AUTH_REQUESTS_URL
           .open(this)
           .as(JsonArray.class)
           .expect(200, "While loading authorization requests")
           .get();
   for (JsonValue contactRequest : array) {
     JsonObject contactRequestObj = contactRequest.asObject();
     try {
       ContactRequestImpl request =
           new ContactRequestImpl(
               contactRequestObj.get("event_time").asString(),
               getOrLoadContact(contactRequestObj.get("sender").asString()),
               contactRequestObj.get("greeting").asString(),
               this);
       if (!this.allContactRequests.contains(request)) {
         if (fromWebsocket) {
           ContactRequestEvent event = new ContactRequestEvent(request);
           getEventDispatcher().callEvent(event);
         }
         this.allContactRequests.add(request);
       }
     } catch (java.text.ParseException e) {
       getLogger().log(Level.WARNING, "Could not parse date for contact request", e);
     }
   }
   if (fromWebsocket) this.updateContactList();
 }
示例#4
0
 @Override
 public void updateContactList() throws ConnectionException {
   JsonObject obj =
       Endpoints.GET_ALL_CONTACTS
           .open(this, getUsername(), "notification")
           .as(JsonObject.class)
           .expect(200, "While loading contacts")
           .get();
   for (JsonValue value : obj.get("contacts").asArray()) {
     if (value.asObject().get("suggested") == null
         || !value.asObject().get("suggested").asBoolean()) {
       String id = value.asObject().get("id").asString();
       ContactImpl impl = (ContactImpl) allContacts.get(id);
       impl.update(value.asObject());
     }
   }
 }
  /** Tests the result of the rest api GET when there is a config. */
  @Test
  public void testConfigs() {
    setUpConfigData();
    final WebTarget wt = target();
    final String response = wt.path("network/configuration").request().get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    Assert.assertThat(result, notNullValue());

    Assert.assertThat(result.names(), hasSize(2));

    JsonValue devices = result.get("devices");
    Assert.assertThat(devices, notNullValue());

    JsonValue device1 = devices.asObject().get("device1");
    Assert.assertThat(device1, notNullValue());

    JsonValue basic = device1.asObject().get("basic");
    Assert.assertThat(basic, notNullValue());

    checkBasicAttributes(basic);
  }
示例#6
0
  @Override
  public void generateBuildScript(Configuration cfg, Context ctx) {
    try {
      final InputStream input =
          this.getClass().getClassLoader().getResourceAsStream("javascript/lib/package.json");
      final List<String> packLines = IOUtils.readLines(input);
      String pack = "";
      for (String line : packLines) {
        pack += line + "\n";
      }
      input.close();
      pack = pack.replace("<NAME>", cfg.getName());

      final JsonObject json = JsonObject.readFrom(pack);
      final JsonValue deps = json.get("dependencies");
      for (Thing t : cfg.allThings()) {
        for (String dep : t.annotation("js_dep")) {
          deps.asObject().add(dep.split(":")[0].trim(), dep.split(":")[1].trim());
        }
      }

      for (Thing t : cfg.allThings()) {
        if (t.getStreams().size() > 0) {
          deps.asObject().add("rx", "^2.5.3");
          deps.asObject().add("events", "^1.0.2");
          break;
        }
      }

      final File f = new File(ctx.getOutputDirectory() + "/" + cfg.getName() + "/package.json");
      f.setWritable(true);
      final PrintWriter w = new PrintWriter(new FileWriter(f));
      w.println(json.toString());
      w.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 @Override
 protected void parseMember(JsonObject.Member member) {
   super.parseMember(member);
   try {
     JsonValue value = member.getValue();
     String memberName = member.getName();
     if ("small".equals(memberName)) {
       OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.SMALL);
       small = thumbnail.new Metadata(value.asObject());
     } else if ("medium".equals(memberName)) {
       OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.MEDIUM);
       medium = thumbnail.new Metadata(value.asObject());
     } else if ("large".equals(memberName)) {
       OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.LARGE);
       large = thumbnail.new Metadata(value.asObject());
     } else if ("source".equals(memberName)) {
       OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.SOURCE);
       source = thumbnail.new Metadata(value.asObject());
     }
   } catch (ParseException e) {
     throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
   }
 }
示例#8
0
 @Override
 public void loadAllContacts() throws ConnectionException {
   JsonObject object =
       Endpoints.GET_ALL_CONTACTS
           .open(this, getUsername(), "default")
           .as(JsonObject.class)
           .expect(200, "While loading contacts")
           .get();
   for (JsonValue value : object.get("contacts").asArray()) {
     JsonObject obj = value.asObject();
     if (obj.get("suggested") == null || !obj.get("suggested").asBoolean()) {
       if (!allContacts.containsKey(obj.get("id").asString())) {
         this.allContacts.put(obj.get("id").asString(), new ContactImpl(this, obj));
       }
     }
   }
 }
 private void checkBasicAttributes(JsonValue basic) {
   Assert.assertThat(basic.asObject().get("field1").asString(), is("v1"));
   Assert.assertThat(basic.asObject().get("field2").asString(), is("v2"));
 }