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);
}
}
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");
}
}
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);
}
}
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;
}
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");
}
}
}
Aggregations