use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class TestEntityManager method testGetEntityTypes.
public void testGetEntityTypes() throws Throwable {
if (null == this._entityManager)
return;
Map<String, AttributeInterface> attributes = this._entityManager.getEntityAttributePrototypes();
String testTypeCode = "XXX";
String testAttributeName = "testAttributeName";
Map<String, IApsEntity> entityTypes = this._entityManager.getEntityPrototypes();
try {
assertNotNull(entityTypes);
assertTrue(entityTypes.size() > 0);
assertNull(entityTypes.get(testTypeCode));
IApsEntity entityPrototype = new ArrayList<IApsEntity>(entityTypes.values()).get(0);
int initAttributeNumber = entityPrototype.getAttributeList().size();
entityPrototype.setTypeCode(testTypeCode);
entityPrototype.setTypeDescr("testDescription");
assertNull(entityPrototype.getAttribute(testAttributeName));
AttributeInterface newAttribute = attributes.get("Text");
newAttribute.setName(testAttributeName);
newAttribute.setRequired(true);
entityPrototype.addAttribute(newAttribute);
((IEntityTypesConfigurer) this._entityManager).addEntityPrototype(entityPrototype);
entityTypes = this._entityManager.getEntityPrototypes();
IApsEntity extractedEntityPrototype = entityTypes.get(testTypeCode);
assertNotNull(extractedEntityPrototype);
assertEquals(initAttributeNumber + 1, extractedEntityPrototype.getAttributeList().size());
} catch (Throwable t) {
throw t;
} finally {
((IEntityTypesConfigurer) this._entityManager).removeEntityPrototype(testTypeCode);
entityTypes = this._entityManager.getEntityPrototypes();
assertNull(entityTypes.get(testTypeCode));
}
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiUserProfileInterface method addUserProfile.
public StringApiResponse addUserProfile(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 + "' already 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().addProfile(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 adding user profile", t);
// ApsSystemUtils.logThrowable(t, this, "addUserProfile");
throw new ApsSystemException("Error adding 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 updateUserProfileType.
public StringApiResponse updateUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbProfileType.getTypeCode();
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");
}
Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
((IEntityTypesConfigurer) this.getUserProfileManager()).updateEntityPrototype(profileType);
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 type", t);
// ApsSystemUtils.logThrowable(t, this, "updateProfileType");
throw new ApsSystemException("Error updating user profile type", t);
}
return response;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class ApiUserProfileTypeInterface method addUserProfileType.
public StringApiResponse addUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbProfileType.getTypeCode();
IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
if (null != masterProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' already exists");
}
if (typeCode == null || typeCode.length() != 3) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
}
Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
((IEntityTypesConfigurer) this.getUserProfileManager()).addEntityPrototype(profileType);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error adding user profile type", t);
// ApsSystemUtils.logThrowable(t, this, "addProfileType");
throw new ApsSystemException("Error adding user profile type", t);
}
return response;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class DataObjectListHelper method getConfiguredUserFilters.
@Override
public List<UserFilterOptionBean> getConfiguredUserFilters(IDataObjectListTagBean bean, RequestContext reqCtx) throws ApsSystemException {
List<UserFilterOptionBean> userEntityFilters = null;
try {
Widget widget = (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET);
ApsProperties config = (null != widget) ? widget.getConfig() : null;
if (null == config || null == config.getProperty(WIDGET_PARAM_CONTENT_TYPE)) {
return null;
}
String dataObjectTypeCode = config.getProperty(WIDGET_PARAM_CONTENT_TYPE);
IApsEntity prototype = this.getDataObjectManager().getEntityPrototype(dataObjectTypeCode);
if (null == prototype) {
_logger.error("Null dataObject type by code '{}'", dataObjectTypeCode);
return null;
}
Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
String userFilters = config.getProperty(WIDGET_PARAM_USER_FILTERS);
if (null != userFilters && userFilters.length() > 0) {
userEntityFilters = FilterUtils.getUserFilters(userFilters, currentFrame, currentLang, prototype, this.getUserFilterDateFormat(), reqCtx.getRequest());
}
} catch (Throwable t) {
_logger.error("Error extracting user filters", t);
throw new ApsSystemException("Error extracting user filters", t);
}
return userEntityFilters;
}
Aggregations