Search in sources :

Example 6 with IEntityTypesConfigurer

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

the class AbstractEntityService method updateEntityType.

protected synchronized O updateEntityType(String entityManagerCode, EntityTypeDtoRequest request, BindingResult bindingResult) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    try {
        if (null == entityManager.getEntityPrototype(request.getCode())) {
            this.addError(EntityTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, bindingResult, new String[] { request.getCode() }, "entityType.notExists");
            return null;
        }
        IDtoBuilder<I, O> builder = this.getEntityTypeFullDtoBuilder(entityManager);
        I entityPrototype = this.createEntityType(entityManager, request, bindingResult);
        if (bindingResult.hasErrors()) {
            return null;
        } else {
            ((IEntityTypesConfigurer) entityManager).updateEntityPrototype(entityPrototype);
            I newPrototype = (I) entityManager.getEntityPrototype(request.getCode());
            O newType = builder.convert(newPrototype);
            newType.setStatus(String.valueOf(entityManager.getStatus(request.getCode())));
            return newType;
        }
    } catch (Throwable e) {
        logger.error("Error updating entity type", e);
        throw new RestServerError("error updating entity type", e);
    }
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 7 with IEntityTypesConfigurer

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

the class TestUserProfileAction method testEditProfile_3.

public void testEditProfile_3() throws Throwable {
    IUserProfile prototype = this._profileManager.getDefaultProfileType();
    prototype.setTypeCode("XXX");
    ((IEntityTypesConfigurer) this._profileManager).addEntityPrototype(prototype);
    try {
        this.setUserOnSession("admin");
        this.initAction("/do/userprofile", "edit");
        this.addParameter("username", USERNAME_FOR_TEST);
        String result = this.executeAction();
        assertEquals("chooseType", result);
        IUserProfile currentUserProfile = (IUserProfile) this.getRequest().getSession().getAttribute(UserProfileAction.USERPROFILE_ON_SESSION);
        assertNull(currentUserProfile);
    } catch (Throwable t) {
        throw t;
    } finally {
        ((IEntityTypesConfigurer) this._profileManager).removeEntityPrototype("XXX");
    }
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 8 with IEntityTypesConfigurer

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

the class TestEntityManagersAction method testSaveNewAttribute.

public void testSaveNewAttribute() throws Throwable {
    // Search an entity manager
    String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
    if (null == defNames || defNames.length == 0)
        return;
    String entityManagerName = defNames[0];
    IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
    // get the entites managed by the ApsEntityManager
    Map<String, IApsEntity> entities = entityManager.getEntityPrototypes();
    if (null == entities || entities.size() == 0)
        return;
    List<String> enitiesTypeCodes = new ArrayList<String>();
    enitiesTypeCodes.addAll(entities.keySet());
    // get the first entity type code available
    String entityTypeCode = enitiesTypeCodes.get(0);
    try {
        // wrong name
        String attributeName = "wrong name";
        String attributeTypeCode = "Monotext";
        int strutsAction = ApsAdminSystemConstants.ADD;
        String result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, null, null, entityManagerName);
        assertEquals(Action.INPUT, result);
        EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
        Map<String, List<String>> fieldErrors = action.getFieldErrors();
        assertEquals(1, fieldErrors.size());
        assertTrue(fieldErrors.containsKey("attributeName"));
        // wrong length
        attributeName = "right_name";
        result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, 3, 5, entityManagerName);
        assertEquals(Action.INPUT, result);
        fieldErrors = action.getFieldErrors();
        assertEquals(1, fieldErrors.size());
        assertTrue(fieldErrors.containsKey("minLength"));
        // insert ok
        attributeName = "right_name";
        result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, 5, 3, entityManagerName);
        assertEquals(Action.SUCCESS, result);
        IApsEntity entity = entityManager.getEntityPrototype(entityTypeCode);
        assertTrue(entity.getAttributeMap().containsKey("right_name"));
        // duplicate attribute name
        attributeName = "right_name";
        result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, null, null, entityManagerName);
        assertEquals(Action.INPUT, result);
        fieldErrors = action.getFieldErrors();
        assertEquals(1, fieldErrors.size());
        assertTrue(fieldErrors.containsKey("attributeName"));
    } catch (Throwable t) {
    // nothing to do
    } finally {
        IApsEntity entity = entityManager.getEntityPrototype(entityTypeCode);
        entity.getAttributeMap().remove("right_name");
        ((IEntityTypesConfigurer) entityManager).updateEntityPrototype(entity);
    }
}
Also used : ArrayList(java.util.ArrayList) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ArrayList(java.util.ArrayList) List(java.util.List) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) EntityAttributeConfigAction(com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)

Example 9 with IEntityTypesConfigurer

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

the class EntityTypesAction method removeEntityType.

@Override
public String removeEntityType() {
    try {
        String checkResult = this.checkDelete();
        if (null != checkResult)
            return checkResult;
        IEntityTypesConfigurer entityManager = (IEntityTypesConfigurer) this.getEntityManager();
        entityManager.removeEntityPrototype(this.getEntityTypeCode());
    } catch (Throwable t) {
        _logger.error("error in removeEntityType", t);
        // ApsSystemUtils.logThrowable(t, this, "removeEntityType");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 10 with IEntityTypesConfigurer

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

the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_1.

@Test
public void testAddUpdateUserProfileType_1() throws Exception {
    try {
        Assert.assertNull(this.userProfileManager.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("/profileTypes").content(jsonPost).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isOk());
        Assert.assertNotNull(this.userProfileManager.getEntityPrototype("AAA"));
        UserProfile addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
        Assert.assertEquals("Profile 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("/profileTypes/{profileTypeCode}", 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("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isOk());
        addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
        Assert.assertEquals("Profile Type AAA Modified", addedType.getTypeDescription());
        Assert.assertEquals(2, addedType.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("AAA")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("AAA");
        }
    }
}
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)

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