Exemple #1
0
 @Override
 public void readMember(RequestContext ctx, String id, Responder responder) throws Exception {
   if (scriptFileResource != null && id.equals(scriptFileResource.id())) {
     responder.resourceRead(scriptFileResource);
   } else {
     responder.noSuchResource(id);
   }
 }
Exemple #2
0
 @Override
 public void readMember(RequestContext ctx, String id, Responder responder) throws Exception {
   Script script = scripts.get(id);
   if (script != null) {
     responder.resourceRead(new ResourceScript(this, script));
   } else {
     responder.noSuchResource(id);
   }
 }
Exemple #3
0
 public void deleteMember(RequestContext ctx, String id, Responder responder) throws Exception {
   Script script = scripts.get(id);
   if (script != null) {
     if (script.getScriptBuffer() != null) {
       deleteSourceFile(id);
     }
     deleteMetadataFile(id);
     deleteScriptDirectory(id);
     scripts.remove(id);
     responder.resourceDeleted(new ResourceScript(this, script));
   } else {
     responder.noSuchResource(id);
   }
 }
Exemple #4
0
  @Override
  public void createMember(RequestContext ctx, ResourceState state, Responder responder)
      throws Exception {

    if (state instanceof LazyResourceState) {
      LazyResourceState lazyResourceState = (LazyResourceState) state;
      ByteBuf content = lazyResourceState.contentAsByteBuf();
      setScriptFile(content.copy());

      parent.writeSourceFile(this.id(), content.copy());

      responder.resourceCreated(scriptFileResource);
      return;
    }
    responder.invalidRequest("The uploaded script must be a binary javascript file.");
  }
Exemple #5
0
  @Override
  public void createMember(RequestContext ctx, ResourceState state, Responder responder)
      throws Exception {
    try {
      ResourceScript resourceScript = new ResourceScript(this, state);

      scripts.add(resourceScript.getScript());

      // Write to the file system
      ObjectNode objectNode = ConversionUtils.convert(state);
      writeMetadataFile(resourceScript.id(), objectNode);

      responder.resourceCreated(resourceScript);
    } catch (InvalidPropertyTypeException e) {
      responder.invalidRequest(e.getMessage());
    }
  }
Exemple #6
0
  public void deleteMember(RequestContext ctx, String id, Responder responder) throws Exception {
    parent.getResourceInterceptorManager().removeResource(this.id);
    parent.deleteSourceFile(this.id);

    responder.resourceDeleted(this.scriptFileResource);

    this.scriptFileResource = null;
  }
  @Override
  public void readMember(RequestContext ctx, String id, Responder responder) {
    try {
      if (id == null) {
        responder.resourceRead(this);
        return;
      }

      if (!this.resources.containsKey(id)) {
        responder.noSuchResource(id);
        return;
      }

      responder.resourceRead(this.resources.get(id));

    } catch (Throwable t) {
      responder.internalError(t.getMessage());
    }
  }
Exemple #8
0
  @Override
  public void updateProperties(RequestContext ctx, ResourceState state, Responder responder)
      throws Exception {
    // TODO: put this code in a common location since its also used when creating
    Object nameProperty = state.getProperty(NAME);
    if (nameProperty != null) {
      name = nameProperty.toString();
    } else {
      name = null;
    }

    Object descriptionProperty = state.getProperty(DESCRIPTION);
    if (descriptionProperty != null) {
      description = descriptionProperty.toString();
    } else {
      description = null;
    }

    Object enabledProperty = state.getProperty(ENABELD);
    if (enabledProperty != null && enabledProperty instanceof Boolean) {
      enabled = (Boolean) enabledProperty;
    } else {
      enabled = false;
    }

    libraries.clear();
    Object libraries = state.getProperty(LIBRARIES);
    if (libraries != null && libraries instanceof List) {
      for (Object entry : (List) libraries) {
        if (entry instanceof String) {
          this.libraries.add((String) entry);
        }
      }
    } else if (libraries != null) {
      throw new InvalidPropertyTypeException(LIBRARIES, List.class);
    }

    Object targetProperty = state.getProperty(TARGET_PATH);
    if (targetProperty != null && targetProperty instanceof String) {
      target = (String) targetProperty;
    } else {
      throw new InvalidPropertyTypeException(TARGET_PATH, String.class);
    }

    Object priorityProperty = state.getProperty(PRIORITY);
    if (priorityProperty != null && priorityProperty instanceof Integer) {
      priority = (Integer) priorityProperty;
    } else if (priorityProperty != null) {
      throw new InvalidPropertyTypeException(PRIORITY, Integer.class);
    }

    parent.getResourceInterceptorManager().addResource(this);
    parent.writeMetadataFile(this.id(), ConversionUtils.convert(state));
    responder.resourceUpdated(this);
  }
  @Override
  public void updateProperties(RequestContext ctx, ResourceState state, Responder responder)
      throws Exception {
    String name = (String) state.getProperty("name");
    if (name != null && !name.isEmpty()) {
      this.app.setName(name);
    }

    Boolean visible = (Boolean) state.getProperty("visible");
    if (visible != null) {
      this.app.setVisible(visible);
    }

    String htmlPath = (String) state.getProperty("html-app");
    if (htmlPath != null) {
      if (!htmlPath.startsWith("/" + this.app.id())) {
        htmlPath = "/" + this.app.id() + htmlPath;
      }
      this.app.setHtmlApplicationPath(htmlPath);
    }

    String versionResourceId = (String) state.getProperty("version-resource-id");
    if (versionResourceId != null) {
      boolean resourceFound = false;
      for (Resource resource : this.extensions.members(ctx)) {
        if (resource.id().equals(versionResourceId)) {
          resourceFound = true;
          break;
        }
      }
      if (!resourceFound) {
        throw new PropertyException("No versioning resource found with id: " + versionResourceId);
      }
      this.app.setVersionResourceId(versionResourceId);
    }

    this.configManager.updateApplication(this.app);

    Boolean partOfGitInstallProcess = (Boolean) state.getProperty("git-install-process");
    if (this.app.versioned() && (partOfGitInstallProcess == null || !partOfGitInstallProcess)) {
      // Wrap current responder with one that will perform commit of version changes
      responder =
          new ConfigVersioningResponder(
              responder,
              app.versioned(),
              app.versionedResourcePath(),
              this.client,
              ctx.securityContext());
    }

    responder.resourceUpdated(this);
  }
 @Override
 public void delete(RequestContext ctx, Responder responder) throws Exception {
   this.appRegistry.removeApplication(id());
   responder.resourceDeleted(this);
 }