private ObjectNode getPolicyConfig() throws Exception {
   ObjectMapper om = ObjectMapperFactory.create();
   ObjectNode objectNode =
       om.readValue(
           getClass().getClassLoader().getResourceAsStream("policy-config/uri-policy-config.json"),
           ObjectNode.class);
   return objectNode;
 }
Esempio n. 2
0
 public void writeMetadataFile(String id, ObjectNode objectNode) throws Exception {
   File scriptDirectory = new File(resourceDirectory.getPath() + File.separator + id);
   if (!scriptDirectory.exists()) {
     scriptDirectory.mkdir();
   }
   File metadataFile = new File(scriptDirectory.getPath() + File.separator + METADATA_FILENAME);
   ObjectMapperFactory.createWriter().writeValue(metadataFile, objectNode);
 }
Esempio n. 3
0
  // Read the configuration files from the filesystem [if any] and configure the resource based on
  // them
  public void start() throws IOException {

    // get a reference to where the resource triggred scripts should be held
    String resourceBasedDir = parent.getScriptDirectory() + File.separator + "/" + RESOURCE_DIRNAME;
    resourceDirectory = new File(resourceBasedDir);

    // create the directory if it doesn't already exist
    if (!resourceDirectory.exists()) {
      resourceDirectory.mkdirs();
    }

    vertx
        .fileSystem()
        .readDir(
            resourceDirectory.getPath(),
            (result) -> {
              if (!result.failed()) {

                for (String fileName : result.result()) {
                  File scriptDirectory = new File(fileName);
                  String resourceID = scriptDirectory.getName();

                  try {
                    // read the file containing the metadata for this script
                    File metadataFile =
                        new File(
                            scriptDirectory.getPath() + File.separator + "/" + METADATA_FILENAME);
                    if (metadataFile.exists()) {
                      ObjectNode objectNode =
                          (ObjectNode) ObjectMapperFactory.create().readTree(metadataFile);

                      ResourceState state = ConversionUtils.convert(objectNode);
                      state.id(resourceID);

                      ResourceScript resourceScript = new ResourceScript(this, state);
                      // add this resource to the list of scripts available.
                      this.scripts.add(resourceScript.getScript());

                      // read the file containing the source for this script [if any]
                      File sourceFile =
                          new File(
                              scriptDirectory.getPath() + File.separator + "/" + SOURCE_FILENAME);
                      if (sourceFile.exists()) {
                        vertx
                            .fileSystem()
                            .readFile(
                                sourceFile.getPath(),
                                (buffer) -> {
                                  resourceScript
                                      .getScript()
                                      .setScriptBuffer(buffer.result().getByteBuf());
                                });
                      }
                    }
                  } catch (Exception e) {
                    logger().error("Error reading resource script files.", e);
                  }
                }

              } else {
                logger().error("Error reading resource script files.", result.cause());
              }
            });
  }