Search in sources :

Example 1 with SOAEvent

use of org.jaffa.soa.domain.SOAEvent in project jaffa-framework by jaffa-projects.

the class SOAEventParam method validate.

// .//GEN-END:performPreDeleteReferentialIntegrity_1_be
// .//GEN-BEGIN:3_be
/**
 * @clientCardinality 0..*
 * @supplierCardinality 1
 * @clientQualifier eventId
 * @supplierQualifier eventId
 * @link association
 */
/*#SOAEvent lnkSOAEvent;*/
// .//GEN-END:3_be
// All the custom code goes here//GEN-FIRST:custom
/**
 * {@inheritDoc}
 */
@Override
public void validate() throws ApplicationExceptions, FrameworkException {
    // Ensure that the eventId is specified
    if (getEventId() == null)
        throw new ApplicationExceptions(new MandatoryFieldException(SOAEventParamMeta.META_EVENT_ID.getLabelToken()));
    // Log a WARNing message if the paramter is not documented in soa-events.xml
    if (getName() != null && isModified(SOAEventParamMeta.NAME)) {
        try {
            SOAEvent soaEvent = getSOAEventObject();
            SoaEventInfo soaEventInfo = ConfigurationService.getInstance().getSoaEventInfo(soaEvent.getEventName());
            if (soaEventInfo != null) {
                boolean foundParam = false;
                for (Param param : soaEventInfo.getParam()) {
                    if (getName().equals(param.getName())) {
                        foundParam = true;
                        break;
                    }
                }
                if (!foundParam)
                    log.warn("SOA Event Parameter'" + soaEvent.getEventName() + ": " + getName() + "' should be documented in soa-events.xml");
            }
        } catch (ValidationException e) {
            throw new ApplicationExceptions(e);
        }
    }
    super.validate();
}
Also used : SoaEventInfo(org.jaffa.soa.services.configdomain.SoaEventInfo) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException) Param(org.jaffa.soa.services.configdomain.Param) SOAEvent(org.jaffa.soa.domain.SOAEvent)

Example 2 with SOAEvent

use of org.jaffa.soa.domain.SOAEvent in project jaffa-framework by jaffa-projects.

the class SOAEventParam method findSOAEventObject.

/**
 * Finds the related foreign SOAEvent 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 findSOAEventObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_sOAEventObject == null && getEventId() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(SOAEventMeta.getName());
            criteria.addCriteria(SOAEventMeta.EVENT_ID, getEventId());
            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_sOAEventObject = (SOAEvent) itr.next();
            }
            if (m_sOAEventObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(SOAEventParamMeta.META_EVENT_ID.getLabelToken(), new Object[] { SOAEventMeta.getLabelToken(), SOAEventMeta.META_EVENT_ID.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) SOAEvent(org.jaffa.soa.domain.SOAEvent)

Aggregations

SOAEvent (org.jaffa.soa.domain.SOAEvent)2 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 Param (org.jaffa.soa.services.configdomain.Param)1 SoaEventInfo (org.jaffa.soa.services.configdomain.SoaEventInfo)1