Search in sources :

Example 16 with IEntityTypesConfigurer

use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.

the class DataTypeControllerIntegrationTest method testAddUpdateDataType_1.

@Test
public void testAddUpdateDataType_1() throws Exception {
    try {
        Assert.assertNull(this.dataObjectManager.getEntityPrototype("AAA"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        InputStream isJsonPost = this.getClass().getResourceAsStream("1_POST_valid.json");
        String jsonPost = FileTextReader.getText(isJsonPost);
        ResultActions result1 = mockMvc.perform(post("/dataTypes").content(jsonPost).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isOk());
        DataObject addedType = (DataObject) this.dataObjectManager.getEntityPrototype("AAA");
        Assert.assertNotNull(addedType);
        Assert.assertEquals("Type AAA", addedType.getTypeDescription());
        Assert.assertEquals(1, addedType.getAttributeList().size());
        InputStream isJsonPutInvalid = this.getClass().getResourceAsStream("1_PUT_invalid.json");
        String jsonPutInvalid = FileTextReader.getText(isJsonPutInvalid);
        ResultActions result2 = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).content(jsonPutInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2.andExpect(status().isBadRequest());
        InputStream isJsonPutValid = this.getClass().getResourceAsStream("1_PUT_valid.json");
        String jsonPutValid = FileTextReader.getText(isJsonPutValid);
        ResultActions result3 = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isOk());
        addedType = (DataObject) this.dataObjectManager.getEntityPrototype("AAA");
        Assert.assertEquals("Type AAA Modified", addedType.getTypeDescription());
        Assert.assertEquals(2, addedType.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.dataObjectManager.getEntityPrototype("AAA"));
    } finally {
        if (null != this.dataObjectManager.getEntityPrototype("AAA")) {
            ((IEntityTypesConfigurer) this.dataObjectManager).removeEntityPrototype("AAA");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 17 with IEntityTypesConfigurer

use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.

the class DataTypeControllerIntegrationTest method testAddUpdateDataType_2.

@Test
public void testAddUpdateDataType_2() throws Exception {
    try {
        Assert.assertNull(this.dataObjectManager.getEntityPrototype("TST"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        InputStream isJsonPostInvalid = this.getClass().getResourceAsStream("2_POST_invalid.json");
        String jsonPostInvalid = FileTextReader.getText(isJsonPostInvalid);
        ResultActions result1 = mockMvc.perform(post("/dataTypes").content(jsonPostInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isBadRequest());
        Assert.assertNull(this.dataObjectManager.getEntityPrototype("TST"));
        InputStream isJsonPostValid = this.getClass().getResourceAsStream("2_POST_valid.json");
        String jsonPostValid = FileTextReader.getText(isJsonPostValid);
        ResultActions result2 = mockMvc.perform(post("/dataTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2.andExpect(status().isOk());
        DataObject addedDataObject = (DataObject) this.dataObjectManager.getEntityPrototype("TST");
        Assert.assertNotNull(addedDataObject);
        Assert.assertEquals(3, addedDataObject.getAttributeList().size());
        ResultActions result2_bis = mockMvc.perform(post("/dataTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2_bis.andExpect(status().isConflict());
        InputStream isJsonPutValid = this.getClass().getResourceAsStream("2_PUT_valid.json");
        String jsonPutValid = FileTextReader.getText(isJsonPutValid);
        ResultActions result3 = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isBadRequest());
        ResultActions result3_bis = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "TST" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3_bis.andExpect(status().isOk());
        DataObject modifiedDataObject = (DataObject) this.dataObjectManager.getEntityPrototype("TST");
        Assert.assertNotNull(modifiedDataObject);
        Assert.assertEquals(5, modifiedDataObject.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/dataTypes/{dataTypeCode}", new Object[] { "TST" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.dataObjectManager.getEntityPrototype("TST"));
    } finally {
        if (null != this.dataObjectManager.getEntityPrototype("TST")) {
            ((IEntityTypesConfigurer) this.dataObjectManager).removeEntityPrototype("TST");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 18 with IEntityTypesConfigurer

use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.

the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_2.

@Test
public void testAddUpdateUserProfileType_2() throws Exception {
    try {
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        InputStream isJsonPostInvalid = this.getClass().getResourceAsStream("2_POST_invalid.json");
        String jsonPostInvalid = FileTextReader.getText(isJsonPostInvalid);
        ResultActions result1 = mockMvc.perform(post("/profileTypes").content(jsonPostInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isBadRequest());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
        InputStream isJsonPostValid = this.getClass().getResourceAsStream("2_POST_valid.json");
        String jsonPostValid = FileTextReader.getText(isJsonPostValid);
        ResultActions result2 = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2.andExpect(status().isOk());
        UserProfile addedDataObject = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
        Assert.assertNotNull(addedDataObject);
        Assert.assertEquals(3, addedDataObject.getAttributeList().size());
        ResultActions result2_bis = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2_bis.andExpect(status().isConflict());
        InputStream isJsonPutValid = this.getClass().getResourceAsStream("2_PUT_valid.json");
        String jsonPutValid = FileTextReader.getText(isJsonPutValid);
        ResultActions result3 = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isBadRequest());
        ResultActions result3_bis = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3_bis.andExpect(status().isOk());
        UserProfile modifiedDataObject = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
        Assert.assertNotNull(modifiedDataObject);
        Assert.assertEquals(5, modifiedDataObject.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("TST")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("TST");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 19 with IEntityTypesConfigurer

use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.

the class ApiEntityTypeInterface method deleteEntityType.

public void deleteEntityType(Properties properties) throws Throwable {
    try {
        String typeCode = properties.getProperty(this.getTypeCodeParamName());
        IApsEntity masterEntityType = this.getEntityManager().getEntityPrototype(typeCode);
        if (null == masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
        }
        EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
        List<String> entityIds = this.getEntityManager().searchId(new EntitySearchFilter[] { filter });
        if (null != entityIds && !entityIds.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " '" + typeCode + "' are used into " + entityIds.size() + " entities");
        }
        this.checkEntityTypeToDelete(masterEntityType);
        ((IEntityTypesConfigurer) this.getEntityManager()).removeEntityPrototype(typeCode);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting Entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteEntityType");
        throw new ApsSystemException("Error deleting Entity type", t);
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)19 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)11 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)6 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 InputStream (java.io.InputStream)4 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)4 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)4 Test (org.junit.Test)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)2 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)2 UserProfile (org.entando.entando.aps.system.services.userprofile.model.UserProfile)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)1