use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiUserProfileInterface method updateUserProfile.
public StringApiResponse updateUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String username = jaxbUserProfile.getId();
if (null == this.getUserProfileManager().getProfile(username)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
}
IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
if (null == profilePrototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
}
IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
List<ApiError> errors = this.validate(userProfile);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
this.getUserProfileManager().updateProfile(username, userProfile);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating user profile", t);
// ApsSystemUtils.logThrowable(t, this, "updateUserProfile");
throw new ApsSystemException("Error updating user profile", t);
}
return response;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiUserProfileTypeInterface method getUserProfileType.
public JAXBUserProfileType getUserProfileType(Properties properties) throws ApiException, Throwable {
JAXBUserProfileType jaxbProfileType = null;
try {
String typeCode = properties.getProperty("typeCode");
IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
if (null == masterProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' does not exist");
}
jaxbProfileType = new JAXBUserProfileType(masterProfileType);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error extracting user profile type", t);
// ApsSystemUtils.logThrowable(t, this, "getProfileType");
throw new ApsSystemException("Error extracting user profile type", t);
}
return jaxbProfileType;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiUserProfileTypeInterface method deleteUserProfileType.
public void deleteUserProfileType(Properties properties) throws ApiException, Throwable {
try {
String typeCode = properties.getProperty("typeCode");
IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
if (null == masterProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' doesn't exist");
}
EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
List<String> profileIds = this.getUserProfileManager().searchId(new EntitySearchFilter[] { filter });
if (null != profileIds && !profileIds.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User profile type '" + typeCode + "' are used into " + profileIds.size() + " profiles");
}
((IEntityTypesConfigurer) this.getUserProfileManager()).removeEntityPrototype(typeCode);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting user Profile type", t);
// ApsSystemUtils.logThrowable(t, this, "deleteProfileType");
throw new ApsSystemException("Error deleting user Profile type", t);
}
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class EntityTypesInfoTag method getMasterObject.
@Override
protected Object getMasterObject(String keyValue) throws Throwable {
String managerNameValue = (String) super.findValue(keyValue, String.class);
try {
IEntityManager entityManager = (IEntityManager) ApsWebApplicationUtils.getBean(managerNameValue, this.pageContext);
if (null != entityManager) {
List<IApsEntity> entityTypes = new ArrayList<IApsEntity>();
Map<String, IApsEntity> typeMap = entityManager.getEntityPrototypes();
if (null != typeMap) {
BeanComparator c = new BeanComparator(this.getOrderBy());
entityTypes.addAll(typeMap.values());
Collections.sort(entityTypes, c);
}
return entityTypes;
} else {
_logger.debug("Null entity manager : service name '{}'", managerNameValue);
}
} catch (Throwable t) {
String message = "Error extracting entity types : entity manager '" + managerNameValue + "'";
_logger.error("Error extracting entity types : entity manager '{}'", managerNameValue, t);
// ApsSystemUtils.logThrowable(t, this, "getMasterObject", message);
throw new ApsSystemException(message, t);
}
return null;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class TestEntityManagersAction method testEditAttribute.
public void testEditAttribute() 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);
List<AttributeInterface> attributes = entities.get(entityTypeCode).getAttributeList();
// get the first attribute
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface currentAttribute = attributes.get(i);
String attributeName = currentAttribute.getName();
String result = this.executeEditAttribute("admin", attributeName, entityTypeCode, entityManagerName);
assertEquals(Action.SUCCESS, result);
EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
assertEquals(currentAttribute.getType(), action.getAttributeTypeCode());
assertEquals(currentAttribute.isRequired(), action.getRequired().booleanValue());
assertEquals(currentAttribute.isSearchable(), action.getSearchable().booleanValue());
assertEquals(currentAttribute.getIndexingType().equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT), action.getIndexable().booleanValue());
if (currentAttribute.isTextAttribute()) {
ITextAttribute attr = (ITextAttribute) currentAttribute;
if (attr.getMaxLength() == -1) {
assertNull(action.getMaxLength());
} else {
assertEquals(attr.getMaxLength(), action.getMaxLength().intValue());
}
if (attr.getMinLength() == -1) {
assertNull(action.getMinLength());
} else {
assertEquals(attr.getMinLength(), action.getMinLength().intValue());
}
assertEquals(attr.getRegexp(), action.getRegexp());
}
assertEquals(ApsAdminSystemConstants.EDIT, action.getStrutsAction());
}
}
Aggregations