Search in sources :

Example 1 with WorkflowDefinitionTO

use of org.apache.syncope.common.lib.to.WorkflowDefinitionTO in project syncope by apache.

the class WorkflowDefPUTResource method newResourceResponse.

@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
    String definition = null;
    try {
        HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
        String requestBody = IOUtils.toString(request.getInputStream());
        String[] split = requestBody.split("&");
        for (int i = 0; i < split.length && definition == null; i++) {
            String keyValue = split[i];
            if (keyValue.startsWith("json_xml=")) {
                definition = UrlUtils.urlDecode(keyValue.split("=")[1]);
            }
        }
    } catch (IOException e) {
        LOG.error("Could not extract workflow definition", e);
    }
    WorkflowDefinitionTO toSet = getWorkflowDefinition(attributes);
    if (definition == null || toSet == null) {
        return new ResourceResponse().setStatusCode(Response.Status.BAD_REQUEST.getStatusCode()).setError(Response.Status.BAD_REQUEST.getStatusCode(), "Could not extract workflow model id and / or definition");
    }
    try {
        restClient.setDefinition(MediaType.APPLICATION_JSON_TYPE, toSet.getKey(), definition);
        return new ResourceResponse().setStatusCode(Response.Status.NO_CONTENT.getStatusCode());
    } catch (Exception e) {
        LOG.error("While updating workflow definition", e);
        return new ResourceResponse().setStatusCode(Response.Status.BAD_REQUEST.getStatusCode()).setError(Response.Status.BAD_REQUEST.getStatusCode(), "While updating workflow definition: " + e.getMessage());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with WorkflowDefinitionTO

use of org.apache.syncope.common.lib.to.WorkflowDefinitionTO in project syncope by apache.

the class WorkflowDirectoryPanel method getActions.

@Override
public ActionsPanel<WorkflowDefinitionTO> getActions(final IModel<WorkflowDefinitionTO> model) {
    final ActionsPanel<WorkflowDefinitionTO> panel = super.getActions(model);
    panel.add(new ActionLink<WorkflowDefinitionTO>() {

        private static final long serialVersionUID = -184018732772021627L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) {
            final IModel<String> wfDefinition = new Model<>();
            try {
                wfDefinition.setObject(IOUtils.toString(restClient.getDefinition(MediaType.APPLICATION_XML_TYPE, model.getObject().getKey())));
            } catch (IOException e) {
                LOG.error("Could not get workflow definition", e);
            }
            utility.header(Model.of(model.getObject().getKey()));
            utility.setContent(new XMLEditorPanel(utility, wfDefinition, false, pageRef) {

                private static final long serialVersionUID = -7688359318035249200L;

                @Override
                public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
                    if (StringUtils.isNotBlank(wfDefinition.getObject())) {
                        try {
                            restClient.setDefinition(MediaType.APPLICATION_XML_TYPE, model.getObject().getKey(), wfDefinition.getObject());
                            SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                            target.add(container);
                            utility.show(false);
                            utility.close(target);
                        } catch (SyncopeClientException e) {
                            SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                        }
                        ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                    }
                }
            });
            utility.show(target);
            target.add(utility);
        }
    }, ActionLink.ActionType.EDIT, StandardEntitlement.WORKFLOW_DEF_SET);
    panel.add(new ActionLink<WorkflowDefinitionTO>() {

        private static final long serialVersionUID = 3109256773218160485L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) {
            modal.header(Model.of(model.getObject().getKey()));
            modal.setContent(new ImageModalPanel<>(modal, restClient.getDiagram(model.getObject().getKey()), pageRef));
            modal.show(target);
            target.add(modal);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.WORKFLOW_DEF_GET);
    panel.add(new ActionLink<WorkflowDefinitionTO>() {

        private static final long serialVersionUID = -184018732772021627L;

        @Override
        public Class<? extends Page> getPageClass() {
            return ModelerPopupPage.class;
        }

        @Override
        public PageParameters getPageParameters() {
            PageParameters parameters = new PageParameters();
            if (modelerCtx != null) {
                parameters.add(Constants.MODELER_CONTEXT, modelerCtx);
            }
            parameters.add(Constants.MODEL_ID_PARAM, model.getObject().getModelId());
            return parameters;
        }

        @Override
        protected boolean statusCondition(final WorkflowDefinitionTO modelObject) {
            return modelerCtx != null;
        }

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) {
        // do nothing
        }
    }, ActionLink.ActionType.WORKFLOW_MODELER, StandardEntitlement.WORKFLOW_DEF_SET);
    panel.add(new ActionLink<WorkflowDefinitionTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        protected boolean statusCondition(final WorkflowDefinitionTO modelObject) {
            return !modelObject.isMain();
        }

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowDefinitionTO ignore) {
            try {
                restClient.deleteDefinition(model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting workflow definition {}", model.getObject().getName(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.WORKFLOW_DEF_DELETE, true);
    return panel;
}
Also used : IModel(org.apache.wicket.model.IModel) XMLEditorPanel(org.apache.syncope.client.console.wicket.markup.html.form.XMLEditorPanel) Form(org.apache.wicket.markup.html.form.Form) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Page(org.apache.wicket.Page) ModelerPopupPage(org.apache.syncope.client.console.pages.ModelerPopupPage) BasePage(org.apache.syncope.client.console.pages.BasePage) IOException(java.io.IOException) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) BasePage(org.apache.syncope.client.console.pages.BasePage) ImageModalPanel(org.apache.syncope.client.console.wicket.markup.html.form.ImageModalPanel)

Example 3 with WorkflowDefinitionTO

use of org.apache.syncope.common.lib.to.WorkflowDefinitionTO in project syncope by apache.

the class AbstractWorkflowResource method getWorkflowDefinition.

protected WorkflowDefinitionTO getWorkflowDefinition(final Attributes attributes) {
    final StringValue modelId = attributes.getRequest().getQueryParameters().getParameterValue(Constants.MODEL_ID_PARAM);
    WorkflowDefinitionTO workflowDefinition = modelId == null || modelId.isNull() ? null : restClient.getDefinitions().stream().filter(object -> modelId.toString().equals(object.getModelId())).findAny().orElse(null);
    if (workflowDefinition == null) {
        throw new NotFoundException("Workflow definition with modelId " + modelId);
    }
    return workflowDefinition;
}
Also used : WorkflowRestClient(org.apache.syncope.client.console.rest.WorkflowRestClient) Logger(org.slf4j.Logger) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) Constants(org.apache.syncope.client.console.commons.Constants) LoggerFactory(org.slf4j.LoggerFactory) AbstractResource(org.apache.wicket.request.resource.AbstractResource) StringValue(org.apache.wicket.util.string.StringValue) NotFoundException(javax.ws.rs.NotFoundException) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) NotFoundException(javax.ws.rs.NotFoundException) StringValue(org.apache.wicket.util.string.StringValue)

Example 4 with WorkflowDefinitionTO

use of org.apache.syncope.common.lib.to.WorkflowDefinitionTO in project syncope by apache.

the class WorkflowDefGETResource method newResourceResponse.

@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
    final WorkflowDefinitionTO toGet = getWorkflowDefinition(attributes);
    ResourceResponse response = new ResourceResponse();
    response.disableCaching();
    response.setContentType(MediaType.APPLICATION_JSON);
    response.setTextEncoding(StandardCharsets.UTF_8.name());
    response.setWriteCallback(new WriteCallback() {

        @Override
        public void writeData(final Attributes attributes) throws IOException {
            IOUtils.copy(new WorkflowRestClient().getDefinition(MediaType.APPLICATION_JSON_TYPE, toGet.getKey()), attributes.getResponse().getOutputStream());
        }
    });
    return response;
}
Also used : WorkflowRestClient(org.apache.syncope.client.console.rest.WorkflowRestClient) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) IOException(java.io.IOException)

Aggregations

WorkflowDefinitionTO (org.apache.syncope.common.lib.to.WorkflowDefinitionTO)4 IOException (java.io.IOException)3 WorkflowRestClient (org.apache.syncope.client.console.rest.WorkflowRestClient)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 NotFoundException (javax.ws.rs.NotFoundException)1 Constants (org.apache.syncope.client.console.commons.Constants)1 BasePage (org.apache.syncope.client.console.pages.BasePage)1 ModelerPopupPage (org.apache.syncope.client.console.pages.ModelerPopupPage)1 ImageModalPanel (org.apache.syncope.client.console.wicket.markup.html.form.ImageModalPanel)1 XMLEditorPanel (org.apache.syncope.client.console.wicket.markup.html.form.XMLEditorPanel)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 Page (org.apache.wicket.Page)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 Form (org.apache.wicket.markup.html.form.Form)1 IModel (org.apache.wicket.model.IModel)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 AbstractResource (org.apache.wicket.request.resource.AbstractResource)1 StringValue (org.apache.wicket.util.string.StringValue)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1