Search in sources :

Example 26 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiResourceAction method updateMethodStatus.

public String updateMethodStatus() {
    try {
        String result = this.checkMethod();
        if (null != result)
            return result;
        ApiMethod method = this.extractMethod();
        String requiredAuthority = this.getRequest().getParameter(method.getHttpMethod().toString() + "_methodAuthority");
        String active = this.getRequest().getParameter(method.getHttpMethod().toString() + "_active");
        String hidden = this.getRequest().getParameter(method.getHttpMethod().toString() + "_hidden");
        if (null == requiredAuthority) {
            // TODO MANAGE
            return SUCCESS;
        }
        this.updateMethodStatus(method, requiredAuthority, active, hidden);
    } catch (Throwable t) {
        _logger.error("Error updating method status", t);
        // ApsSystemUtils.logThrowable(t, this, "updateMethodStatus", "Error updating method status");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 27 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiServiceAction method copyFromWidget.

/**
 * Copy an exist widget (physic and with parameters, joined with a exist api
 * method) and value the form of creation of new api service.
 *
 * @return The result code.
 */
public String copyFromWidget() {
    try {
        String check = this.checkMasterMethod(this.getNamespace(), this.getResourceName());
        if (null != check) {
            return check;
        }
        ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
        // TODO Verify if DRAFT/ONLINE
        IPage page = this.getPageManager().getOnlinePage(this.getPageCode());
        if (null == page) {
            this.addFieldError("pageCode", this.getText("error.service.paste.invalidPageCode", new String[] { this.getPageCode() }));
            return INPUT;
        }
        Widget[] widgets = page.getWidgets();
        if (null == this.getFramePos() || this.getFramePos() > widgets.length || null == widgets[this.getFramePos()]) {
            String framePosString = (null != this.getFramePos()) ? this.getFramePos().toString() : "null";
            this.addFieldError("framePos", this.getText("error.service.paste.invalidFramePos", new String[] { this.getPageCode(), framePosString }));
            return INPUT;
        }
        Widget masterWidget = widgets[this.getFramePos()];
        WidgetType type = (masterWidget.getType().isLogic()) ? masterWidget.getType().getParentType() : masterWidget.getType();
        if (null == masterMethod.getRelatedWidget() || !masterMethod.getRelatedWidget().getWidgetCode().equals(type.getCode())) {
            this.addFieldError("framePos", this.getText("error.service.paste.invalidWidget", new String[] { masterWidget.getType().getCode(), masterMethod.getResourceName() }));
            return INPUT;
        }
        ApsProperties parameters = this.extractParametersFromWidget(masterMethod.getRelatedWidget(), masterWidget);
        this.setApiParameterValues(parameters);
        this.setApiParameters(masterMethod.getParameters());
        this.setStrutsAction(ApsAdminSystemConstants.PASTE);
        this.setServiceKey(this.buildTempKey(masterMethod.getResourceName()));
    } catch (Throwable t) {
        _logger.error("error in copyFromWidget", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Widget(com.agiletec.aps.system.services.page.Widget) ApiMethodRelatedWidget(org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 28 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiServiceAction method checkMasterMethod.

protected String checkMasterMethod(String namespace, String resourceName) throws Throwable {
    if (resourceName == null) {
        this.addActionError(this.getText("error.service.new.masterApiMethod.required"));
        return INPUT;
    }
    ApiMethod masterMethod = this.getMethod(namespace, resourceName);
    if (masterMethod == null) {
        this.addActionError(this.getText("error.service.new.masterApiMethod.invalid"));
        return INPUT;
    }
    if (!masterMethod.isCanSpawnOthers()) {
        if (null != namespace) {
            String[] args = { masterMethod.getResourceName(), masterMethod.getNamespace() };
            this.addActionError(this.getText("error.service.new.masterApiMethod.unspawnable2", args));
        } else {
            String[] args = { masterMethod.getResourceName() };
            this.addActionError(this.getText("error.service.new.masterApiMethod.unspawnable", args));
        }
        return INPUT;
    }
    return null;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 29 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiResourceFinderAction method includeIntoMapping.

@Override
protected boolean includeIntoMapping(ApiResource apiResource) {
    ApiMethod GETMethod = apiResource.getGetMethod();
    ApiMethod POSTMethod = apiResource.getPostMethod();
    ApiMethod PUTMethod = apiResource.getPutMethod();
    ApiMethod DELETEMethod = apiResource.getDeleteMethod();
    return (this.isVisible(GETMethod) || this.isVisible(POSTMethod) || this.isVisible(PUTMethod) || this.isVisible(DELETEMethod));
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 30 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class SelfRestCaller method executePostProcess.

@Override
public int executePostProcess(IPostProcess postProcess) throws InvalidPostProcessResultException, ApsSystemException {
    if (!(postProcess instanceof SelfRestCallPostProcess)) {
        return 0;
    }
    SelfRestCallPostProcess selfRestCall = (SelfRestCallPostProcess) postProcess;
    IResponseBuilder responseBuilder = this.getResponseBuilder();
    try {
        Object result = null;
        ApiMethod method = responseBuilder.extractApiMethod(selfRestCall.getMethod(), selfRestCall.getNamespace(), selfRestCall.getResourceName());
        Properties properties = this.extractParameters(selfRestCall);
        if (method.getHttpMethod().equals(ApiMethod.HttpMethod.GET) || method.getHttpMethod().equals(ApiMethod.HttpMethod.DELETE)) {
            result = responseBuilder.createResponse(method, properties);
        } else {
            String contentBody = this.getContentBody(selfRestCall);
            Object bodyObject = UnmarshalUtils.unmarshal(method, contentBody, selfRestCall.getContentType());
            result = responseBuilder.createResponse(method, bodyObject, properties);
        }
        Response.Status responseStatus = this.extractResponseStatusCode(result);
        if (selfRestCall.isPrintResponse()) {
            this.printResponse(selfRestCall, result, responseStatus, method, properties);
        }
    } catch (InvalidPostProcessResultException t) {
        _logger.error("error in executePostProcess", t);
        // ApsSystemUtils.logThrowable(t, this, "executePostProcess", t.getMessage());
        throw t;
    } catch (Throwable t) {
        _logger.error("Error invoking api method", t);
        // ApsSystemUtils.logThrowable(t, this, "executePostProcess", "Error invoking api method");
        throw new ApsSystemException("Error invoking api method", t);
    }
    return 1;
}
Also used : StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) Response(javax.ws.rs.core.Response) AbstractApiResponse(org.entando.entando.aps.system.services.api.model.AbstractApiResponse) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) InvalidPostProcessResultException(org.entando.entando.aps.system.init.model.InvalidPostProcessResultException) SelfRestCallPostProcess(org.entando.entando.aps.system.init.model.SelfRestCallPostProcess) Properties(java.util.Properties) IResponseBuilder(org.entando.entando.aps.system.services.api.server.IResponseBuilder)

Aggregations

ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)40 Properties (java.util.Properties)11 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 ApsProperties (com.agiletec.aps.util.ApsProperties)6 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)5 ApiService (org.entando.entando.aps.system.services.api.model.ApiService)5 Method (java.lang.reflect.Method)4 HashMap (java.util.HashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 ApiMethodRelatedWidget (org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget)3 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2