use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class PartAdditional method findPartObject.
/**
* Finds the related Part object.
* If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
*/
private void findPartObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_partObject == null && getPart() != null) {
Criteria criteria = new Criteria();
criteria.setTable(PartMeta.getName());
criteria.addCriteria(PartMeta.PART, getPart());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_partObject = (Part) itr.next();
}
if (m_partObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(PartAdditionalMeta.META_PART.getLabelToken(), new Object[] { PartMeta.getLabelToken(), PartMeta.META_PART.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class PartPicture method findPartObject.
/**
* Finds the related Part object.
* If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
*/
private void findPartObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_partObject == null && getPart() != null) {
Criteria criteria = new Criteria();
criteria.setTable(PartMeta.getName());
criteria.addCriteria(PartMeta.PART, getPart());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_partObject = (Part) itr.next();
}
if (m_partObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(PartPictureMeta.META_PART.getLabelToken(), new Object[] { PartMeta.getLabelToken(), PartMeta.META_PART.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class PartRemarksPicture method findPartObject.
/**
* Finds the related Part object.
* If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
*/
private void findPartObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_partObject == null && getPart() != null) {
Criteria criteria = new Criteria();
criteria.setTable(PartMeta.getName());
criteria.addCriteria(PartMeta.PART, getPart());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_partObject = (Part) itr.next();
}
if (m_partObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(PartRemarksPictureMeta.META_PART.getLabelToken(), new Object[] { PartMeta.getLabelToken(), PartMeta.META_PART.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class PartialForeignKeyValidator method validateProperty.
/**
* {@inheritDoc}
*/
@Override
protected void validateProperty(T targetObject, String targetPropertyName, Object targetPropertyValue, List<RuleMetaData> rules, UOW uow) throws ApplicationException, FrameworkException {
if (targetPropertyValue != null) {
for (RuleMetaData rule : rules) {
if (log.isDebugEnabled()) {
log.debug("Applying " + rule + " on " + targetPropertyValue);
}
String domainName = rule.getParameter(PARAMETER_DOMAIN_NAME);
String propName = rule.getParameter(PARAMETER_PROPERTY_NAME);
if (propName == null) {
propName = targetPropertyName;
}
propName = StringHelper.getUpper1(propName);
Criteria c = new Criteria();
c.setTable(domainName);
c.addCriteria(propName, targetPropertyValue);
if (!uow.query(c).iterator().hasNext()) {
String className;
try {
className = Class.forName(domainName).getName();
} catch (ClassNotFoundException e) {
throw new JaffaRulesFrameworkException(e.getMessage(), null, e);
}
// Invalid value. Display the list of valid values in the error message
// It is valid for multiple row to be returned so we don't check for that here
String domainLabel = getObjectLabel(className, null);
String fkLabel = getPropertyLabel(targetObject, targetPropertyName);
String primaryKeyLabel = getPrimaryKeyLabel(className, null);
if (primaryKeyLabel == null) {
primaryKeyLabel = fkLabel.toString();
}
if (log.isDebugEnabled()) {
log.debug("PartialForeignKey validation for the value '" + targetPropertyValue + "' of '" + targetPropertyName + "' failed against the domainObject '" + domainName + '\'');
}
String errorCode = getErrorCode(primaryKeyLabel, rule);
Object[] arguments = getErrorArgumentArray(targetObject, rule);
if (arguments == null) {
arguments = new Object[] { domainLabel, primaryKeyLabel };
}
throw wrapException(new InvalidForeignKeyException(errorCode, arguments), targetObject, rule);
}
}
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class FormDefinition method findFormGroupObject.
/**
* Finds the related foreign FormGroup object.
* If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
*/
private void findFormGroupObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_formGroupObject == null && getFormName() != null) {
Criteria criteria = new Criteria();
criteria.setTable(FormGroupMeta.getName());
criteria.addCriteria(FormGroupMeta.FORM_NAME, getFormName());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_formGroupObject = (FormGroup) itr.next();
}
if (m_formGroupObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(FormDefinitionMeta.META_FORM_NAME.getLabelToken(), new Object[] { FormGroupMeta.getLabelToken(), FormGroupMeta.META_FORM_NAME.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
Aggregations