use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class ForeignKeyFieldValidator method validate.
/**
* The RulesEngine will invoke this method to perform the field validation.
* @throws ValidationException if any validation rule fails.
* @throws FrameworkException if any framework error occurs.
*/
public void validate() throws ValidationException, FrameworkException {
if (getValue() != null) {
UOW uow = getUow();
boolean localUow = (uow == null);
try {
if (localUow)
uow = new UOW();
Criteria c = new Criteria();
c.setTable(getDomainClass());
c.addCriteria(getProperty(), getValue());
Collection col = uow.query(c);
if (col.size() == 0) {
String str = "ForeignKey validation failed for the value '" + getValue() + "' against the domainClass/field - " + getDomainClass() + '/' + getProperty();
log.error(str);
throw new InvalidForeignKeyException(getLabelToken(), new Object[] { getLabelToken(getDomainClass()), getLabelToken(getDomainClass(), getProperty()) });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class Asset method findPartObject.
/**
* Finds the related foreign Part 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 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(AssetMeta.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 Item method findConditionObject.
/**
* Finds the related foreign Condition 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 findConditionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_conditionObject == null && getCondition() != null) {
Criteria criteria = new Criteria();
criteria.setTable(ConditionMeta.getName());
criteria.addCriteria(ConditionMeta.CONDITION, getCondition());
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_conditionObject = (Condition) itr.next();
}
if (m_conditionObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(ItemMeta.META_CONDITION.getLabelToken(), new Object[] { ConditionMeta.getLabelToken(), ConditionMeta.META_CONDITION.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class PartRemarks 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(PartRemarksMeta.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 AuditTransactionObject method findAuditTransactionObject.
/**
* Finds the related foreign AuditTransaction 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 findAuditTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_auditTransactionObject == null && getTransactionId() != null) {
Criteria criteria = new Criteria();
criteria.setTable(AuditTransactionMeta.getName());
criteria.addCriteria(AuditTransactionMeta.TRANSACTION_ID, getTransactionId());
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_auditTransactionObject = (AuditTransaction) itr.next();
}
if (m_auditTransactionObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(AuditTransactionObjectMeta.META_TRANSACTION_ID.getLabelToken(), new Object[] { AuditTransactionMeta.getLabelToken(), AuditTransactionMeta.META_TRANSACTION_ID.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
Aggregations