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 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 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."); }
public void setScriptFile(ByteBuf buffer) { this.scriptFileResource = new ScriptFileResource(this, buffer); parent.getResourceInterceptorManager().addResource(this); }
@Override public void delete(RequestContext ctx, Responder responder) throws Exception { parent.deleteMember(ctx, this.id(), responder); }