Search in sources :

Example 6 with ActionDescriptor

use of com.manydesigns.portofino.actions.ActionDescriptor in project Portofino by ManyDesigns.

the class ActionsAction method create.

@POST
public void create(String actionClassName) throws Exception {
    String actionPath = StringUtils.join(parameters.subList(0, parameters.size() - 1), "/");
    String segment = parameters.get(parameters.size() - 1);
    ActionInstance parentActionInstance = getPageInstance(actionPath);
    ResourceAction parent = parentActionInstance.getActionBean();
    Class actionClass = codeBase.loadClass(actionClassName);
    ActionInfo info = actionRegistry.getInfo(actionClass);
    String scriptTemplate = info.scriptTemplate;
    Class<?> configurationClass = info.configurationClass;
    boolean supportsDetail = info.supportsDetail;
    String className = actionClass.getSimpleName() + "_" + RandomUtil.createRandomId();
    OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext();
    ognlContext.put("generatedClassName", className);
    ognlContext.put("actionClassName", actionClassName);
    String script = OgnlTextFormat.format(scriptTemplate, parent);
    ActionDescriptor action = new ActionDescriptor();
    Object configuration = null;
    if (configurationClass != null) {
        configuration = ReflectionUtil.newInstance(configurationClass);
        if (configuration instanceof ConfigurationWithDefaults) {
            ((ConfigurationWithDefaults) configuration).setupDefaults();
        }
    }
    action.init();
    FileObject directory = parentActionInstance.getChildPageDirectory(segment);
    if (directory.exists()) {
        logger.error("Can't create actionDescriptor - directory {} exists", directory.getName().getPath());
        throw new WebApplicationException(Response.serverError().entity(ElementsThreadLocals.getText("error.creating.page.the.directory.already.exists")).build());
    }
    directory.createFolder();
    logger.debug("Creating the new child actionDescriptor in directory: {}", directory);
    ActionLogic.saveActionDescriptor(directory, action);
    if (configuration != null) {
        ActionLogic.saveConfiguration(directory, configuration);
    }
    FileObject groovyScriptFile = directory.resolveFile("action.groovy");
    groovyScriptFile.createFile();
    try (Writer w = new OutputStreamWriter(groovyScriptFile.getContent().getOutputStream())) {
        w.write(script);
    }
    if (supportsDetail) {
        FileObject detailDir = directory.resolveFile(ActionInstance.DETAIL);
        logger.debug("Creating _detail directory: {}", detailDir);
        detailDir.createFolder();
    }
    logger.info("Created action of type " + actionClassName + " in directory " + directory);
}
Also used : ActionDescriptor(com.manydesigns.portofino.actions.ActionDescriptor) ConfigurationWithDefaults(com.manydesigns.portofino.resourceactions.ConfigurationWithDefaults) ActionInfo(com.manydesigns.portofino.resourceactions.registry.ActionInfo) OgnlContext(ognl.OgnlContext) ActionInstance(com.manydesigns.portofino.resourceactions.ActionInstance) FileObject(org.apache.commons.vfs2.FileObject) OutputStreamWriter(java.io.OutputStreamWriter) FileObject(org.apache.commons.vfs2.FileObject) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) AbstractResourceAction(com.manydesigns.portofino.resourceactions.AbstractResourceAction) ResourceAction(com.manydesigns.portofino.resourceactions.ResourceAction)

Example 7 with ActionDescriptor

use of com.manydesigns.portofino.actions.ActionDescriptor in project Portofino by ManyDesigns.

the class SecurityLogic method calculateActualPermissions.

public static Permissions calculateActualPermissions(ActionInstance instance) {
    List<ActionDescriptor> actionDescriptors = new ArrayList<>();
    while (instance != null) {
        actionDescriptors.add(0, instance.getActionDescriptor());
        instance = instance.getParent();
    }
    return calculateActualPermissions(new Permissions(), actionDescriptors);
}
Also used : ActionDescriptor(com.manydesigns.portofino.actions.ActionDescriptor) ArrayList(java.util.ArrayList) Permissions(com.manydesigns.portofino.actions.Permissions)

Aggregations

ActionDescriptor (com.manydesigns.portofino.actions.ActionDescriptor)7 FileObject (org.apache.commons.vfs2.FileObject)4 Permissions (com.manydesigns.portofino.actions.Permissions)3 ActionInstance (com.manydesigns.portofino.resourceactions.ActionInstance)3 ActionContext (com.manydesigns.portofino.resourceactions.ActionContext)2 CrudConfiguration (com.manydesigns.portofino.resourceactions.crud.configuration.database.CrudConfiguration)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 Map (java.util.Map)2 FileBlob (com.manydesigns.elements.annotations.FileBlob)1 Blob (com.manydesigns.elements.blobs.Blob)1 HierarchicalBlobManager (com.manydesigns.elements.blobs.HierarchicalBlobManager)1 AbstractBlobField (com.manydesigns.elements.fields.AbstractBlobField)1 Field (com.manydesigns.elements.fields.Field)1 FileBlobField (com.manydesigns.elements.fields.FileBlobField)1 ClassAccessor (com.manydesigns.elements.reflection.ClassAccessor)1 MutableHttpServletRequest (com.manydesigns.elements.servlet.MutableHttpServletRequest)1 Group (com.manydesigns.portofino.actions.Group)1 Annotation (com.manydesigns.portofino.model.Annotation)1 Property (com.manydesigns.portofino.model.Property)1