Search in sources :

Example 36 with ApiMethod

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

the class ApiCatalogManager method updateMethodConfig.

@Override
public void updateMethodConfig(ApiMethod apiMethod) throws ApsSystemException {
    try {
        ApiMethod masterMethod = this.checkMethod(apiMethod);
        this.getApiCatalogDAO().saveApiStatus(apiMethod);
        masterMethod.setStatus(apiMethod.getStatus());
        masterMethod.setHidden(apiMethod.getHidden());
        masterMethod.setRequiredAuth(apiMethod.getRequiredAuth());
        String requiredPermission = apiMethod.getRequiredPermission();
        if (null != requiredPermission && requiredPermission.trim().length() > 0) {
            masterMethod.setRequiredPermission(requiredPermission);
        } else {
            masterMethod.setRequiredPermission(null);
        }
        String resourceCode = ApiResource.getCode(masterMethod.getNamespace(), masterMethod.getResourceName());
        ApiResource resource = this.getResourceCacheWrapper().getMasterResource(resourceCode);
        this.getResourceCacheWrapper().updateResource(resource);
    } catch (Throwable t) {
        logger.error("Error error updating api status : resource '{}' method '{}'", apiMethod.getResourceName(), apiMethod.getHttpMethod(), t);
        throw new ApsSystemException("Error updating api status", t);
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 37 with ApiMethod

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

the class ApiCatalogManagerTest method testGetMethod.

@Test
public void testGetMethod() throws Throwable {
    when(resourceCacheWrapper.getMasterResource("getService")).thenReturn(createResource(null, "getService"));
    ApiMethod method = this.apiCatalogManager.getMethod(ApiMethod.HttpMethod.GET, "getService");
    assertNotNull(method);
    assertTrue(method.isActive());
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Test(org.junit.Test)

Example 38 with ApiMethod

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

the class ApiCatalogManagerIntegrationTest method testGetMethod.

public void testGetMethod() throws Throwable {
    ApiMethod method = this.getApiCatalogManager().getMethod(ApiMethod.HttpMethod.GET, "getService");
    assertNotNull(method);
    assertTrue(method.isActive());
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 39 with ApiMethod

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

the class ApiCatalogManagerIntegrationTest method testUpdateMethodStatus.

public void testUpdateMethodStatus() throws Throwable {
    ApiMethod method = this.getApiCatalogManager().getMethod(ApiMethod.HttpMethod.GET, "getService");
    method.setStatus(false);
    this.getApiCatalogManager().updateMethodConfig(method);
    method = this.getApiCatalogManager().getMethod(ApiMethod.HttpMethod.GET, "getService");
    assertFalse(method.isActive());
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 40 with ApiMethod

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

the class TestApiI18nLabelInterface method testCreateNewLabel.

protected void testCreateNewLabel(MediaType mediaType) throws Throwable {
    String key = "TEST_LABEL_KEY";
    String label = this._i18nManager.getLabel(key, "it");
    assertNull(label);
    ApsProperties labels = new ApsProperties();
    labels.put("en", "Test label");
    labels.put("it", "Label di Test");
    JAXBI18nLabel jaxbLabel = new JAXBI18nLabel(key, labels);
    ApiResource labelResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
    ApiMethod postMethod = labelResource.getPostMethod();
    Properties properties = super.createApiProperties("admin", "it", mediaType);
    try {
        Object response = this.getResponseBuilder().createResponse(postMethod, jaxbLabel, properties);
        assertNotNull(response);
        assertTrue(response instanceof StringApiResponse);
        assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
        label = this._i18nManager.getLabel(key, "it");
        assertEquals("Label di Test", label);
    } catch (Exception e) {
        throw e;
    } finally {
        this._i18nManager.deleteLabelGroup(key);
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApsProperties(com.agiletec.aps.util.ApsProperties)

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