Search in sources :

Example 36 with ApiException

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

the class ApiGuiFragmentInterface method getGuiFragment.

public JAXBGuiFragment getGuiFragment(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    JAXBGuiFragment jaxbGuiFragment = null;
    try {
        GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
        if (null == guiFragment) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with id '" + code + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbGuiFragment = new JAXBGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error creating jaxb object of fragment - code '{}'", code, t);
        throw t;
    }
    return jaxbGuiFragment;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 37 with ApiException

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

the class ApiServiceInterface method getService.

public Object getService(Properties properties) throws ApiException {
    Object response = null;
    String key = (String) properties.get("key");
    try {
        ApiService service = this.getApiCatalogManager().getApiService(key);
        if (null == service) {
            throw new ApiException(IApiErrorCodes.API_SERVICE_INVALID, "Service '" + key + "' does not exist");
        }
        if (!service.isActive()) {
            throw new ApiException(IApiErrorCodes.API_SERVICE_ACTIVE_FALSE, "Service '" + key + "' is not active");
        }
        this.checkServiceAuthorization(service, properties, true);
        Properties serviceParameters = new Properties();
        serviceParameters.putAll(service.getParameters());
        Iterator<Object> paramIter = properties.keySet().iterator();
        List<String> reservedParameters = Arrays.asList(SystemConstants.API_RESERVED_PARAMETERS);
        while (paramIter.hasNext()) {
            Object paramName = paramIter.next();
            String paramNameString = paramName.toString();
            if (reservedParameters.contains(paramNameString) || service.isFreeParameter(paramNameString)) {
                serviceParameters.put(paramNameString, properties.get(paramName));
            }
        }
        response = this.getResponseBuilder().createResponse(service.getMaster(), serviceParameters);
    } catch (ApiException e) {
        throw e;
    } catch (Throwable t) {
        _logger.error("Error invocating service - key '{}'", key, t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
    }
    return response;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 38 with ApiException

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

the class DefaultJAXBAttributeType method createAttribute.

public AttributeInterface createAttribute(Map<String, AttributeInterface> attributes) throws ApiException {
    AttributeInterface attribute = null;
    try {
        AttributeInterface master = attributes.get(this.getType());
        if (null == master) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Attribute Type '" + this.getType() + "' does not exist");
        }
        attribute = (AttributeInterface) master.getAttributePrototype();
        Pattern pattern = Pattern.compile("\\w+");
        Matcher matcher = pattern.matcher(this.getName());
        if (null == this.getName() || !matcher.matches()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid name '" + this.getName() + "' of Attribute Type '" + this.getType() + "'");
        }
        attribute.setName(this.getName());
        attribute.setDescription(this.getDescription());
        attribute.setRoles(this.toArray(this.getRoles()));
        if (null != this.getSearchable())
            attribute.setSearchable(this.getSearchable());
        if (null != this.getIndexable())
            attribute.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_TEXT);
        attribute.setValidationRules((IAttributeValidationRules) this.getValidationRules());
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error creating attribute '{}'", this.getName(), t);
        throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Error creating attribute '" + this.getName() + "'");
    }
    return attribute;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 39 with ApiException

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

the class TestApiWidgetTypeInterface method testInvokeAddJaxbWidgetType.

private void testInvokeAddJaxbWidgetType(String newWidgetTypeCode, String widgetToClone, String customSingleGui, boolean expectedSuccess) throws Throwable {
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetToClone);
    assertNotNull(widgetType);
    WidgetType newWidgetType = widgetType.clone();
    assertNull(this._widgetTypeManager.getWidgetType(newWidgetTypeCode));
    newWidgetType.setCode(newWidgetTypeCode);
    try {
        JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(newWidgetType);
        if (null != customSingleGui) {
            jaxbWidgetType.setGui(customSingleGui);
        }
        this._apiWidgetTypeInterface.addWidgetType(jaxbWidgetType);
        if (!expectedSuccess) {
            fail();
        }
        WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(newWidgetTypeCode);
        assertNotNull(extractedWidgetType);
        assertEquals(newWidgetType.getConfig(), extractedWidgetType.getConfig());
        assertEquals(newWidgetType.getMainGroup(), extractedWidgetType.getMainGroup());
        assertEquals(newWidgetType.getTitles(), extractedWidgetType.getTitles());
        assertEquals(newWidgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
        assertFalse(extractedWidgetType.isLocked());
    } catch (ApiException ae) {
        if (expectedSuccess) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(newWidgetTypeCode);
        if (null != codes) {
            for (int i = 0; i < codes.size(); i++) {
                String code = codes.get(i);
                this._guiFragmentManager.deleteGuiFragment(code);
            }
        }
        this._widgetTypeManager.deleteWidgetType(newWidgetTypeCode);
    }
}
Also used : WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 40 with ApiException

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

the class TestApiWidgetTypeInterface method testInvokeGetJaxbWidgetType.

private void testInvokeGetJaxbWidgetType(String widgetTypeCode) throws Throwable {
    Properties properties = new Properties();
    properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
    properties.put("code", widgetTypeCode);
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    try {
        JAXBWidgetType jaxbwt = this._apiWidgetTypeInterface.getWidgetType(properties);
        assertNotNull(jaxbwt);
        assertEquals(widgetTypeCode, jaxbwt.getCode());
        assertEquals(widgetType.getTitles(), jaxbwt.getTitles());
    } catch (ApiException ae) {
        if (null != widgetType) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    }
}
Also used : Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApiException (org.entando.entando.aps.system.services.api.model.ApiException)80 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)49 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)13 ApsProperties (com.agiletec.aps.util.ApsProperties)12 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)11 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)10 ArrayList (java.util.ArrayList)9 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)9 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)9 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)7 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)7 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)5 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)5 Properties (java.util.Properties)4