use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface 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.attribute.AttributeInterface 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.attribute.AttributeInterface 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.attribute.AttributeInterface in project entando-core by entando.
the class DataObjectDAO method addDataObjectRelationsRecord.
/**
* Add a record in the table 'dataobjectrelations' for every resource, page,
* other dataobject, role and category associated to the given dataobject).
*
* @param dataobject The current dataobject.
* @param conn The connection to the database.
* @throws ApsSystemException when connection error are detected.
*/
protected void addDataObjectRelationsRecord(DataObject dataobject, Connection conn) throws ApsSystemException {
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(ADD_DATAOBJECT_REL_RECORD);
this.addCategoryRelationsRecord(dataobject, true, stat);
this.addGroupRelationsRecord(dataobject, stat);
EntityAttributeIterator attributeIter = new EntityAttributeIterator(dataobject);
while (attributeIter.hasNext()) {
AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
}
stat.executeBatch();
} catch (BatchUpdateException e) {
_logger.error("Error saving record into dataobjectrelations {}", dataobject.getId(), e.getNextException());
throw new RuntimeException("Error saving record into dataobjectrelations " + dataobject.getId(), e.getNextException());
} catch (Throwable t) {
_logger.error("Error saving record into dataobjectrelations {}", dataobject.getId(), t);
throw new RuntimeException("Error saving record into dataobjectrelations " + dataobject.getId(), t);
} finally {
closeDaoResources(null, stat);
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class UserFilterOptionBean method getEntityFilter.
public EntitySearchFilter getEntityFilter() throws ApsSystemException {
EntitySearchFilter filter = null;
try {
if (!this.isAttributeFilter() || null == this.getFormFieldValues()) {
return null;
}
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute) {
String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
filter = new EntitySearchFilter(attribute.getName(), true, text, true);
if (attribute.isMultilingual()) {
filter.setLangCode(this.getCurrentLang().getCode());
}
} else if (attribute instanceof DateAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
Date startDate = DateConverter.parseDate(start, this.getDateFormat());
Date endDate = DateConverter.parseDate(end, this.getDateFormat());
filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
} else if (attribute instanceof BooleanAttribute) {
String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
if (null != ignore) {
return null;
} else if (null == value || value.equals("both")) {
// special option for three state Attribute
filter = new EntitySearchFilter(attribute.getName(), true);
filter.setNullOption(true);
} else {
filter = new EntitySearchFilter(attribute.getName(), true, value, false);
}
} else if (attribute instanceof NumberAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
BigDecimal startNumber = null;
try {
Integer startNumberInt = Integer.parseInt(start);
startNumber = new BigDecimal(startNumberInt);
} catch (Throwable t) {
}
BigDecimal endNumber = null;
try {
Integer endNumberInt = Integer.parseInt(end);
endNumber = new BigDecimal(endNumberInt);
} catch (Throwable t) {
}
filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
}
} catch (Throwable t) {
_logger.error("Error extracting entity search filters", t);
throw new ApsSystemException("Error extracting entity search filters", t);
}
return filter;
}
Aggregations