use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentHandler method endBeanClone.
@Override
public void endBeanClone(String path, Object source, Object target, Object newGraph) throws ApplicationException, ApplicationExceptions, FrameworkException {
if (source instanceof AttachmentGraph && target instanceof Attachment) {
AttachmentGraph attachmentGraph = (AttachmentGraph) source;
Attachment attachment = (Attachment) target;
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
if (attachmentDataImpl != null && attachment.getDocumentReferenceId() != null) {
if (attachmentDataImpl.read(attachment.getDocumentReferenceId()) == null) {
attachmentDataImpl.create(attachment.getDocumentReferenceId(), attachmentGraph.getData());
}
}
}
}
use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentMaintenanceTx method prevalidateUpdate.
// .//GEN-END:_retrieve_1_be
// .//GEN-BEGIN:_prevalidateUpdate_1_be
/**
* This method is used to perform prevalidations before updating an existing instance of Attachment.
* @param input The new values for the domain object.
* @throws ApplicationExceptions This will be thrown if the input contains invalid data.
* @throws FrameworkException Indicates some system error.
* @return The object details.
*/
public AttachmentMaintenancePrevalidateOutDto prevalidateUpdate(AttachmentMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled())
log.debug("Input: " + input);
// create the UOW
uow = new UOW();
// Preprocess the input
preprocess(uow, input);
// Retrieve the object
Attachment domain = load(uow, input);
// Ensure the domain object has not been modified
domainObjectChangedTest(input.getPerformDirtyReadCheck(), domain, input.getLastChangedOn());
// Validate the foreign objects
validateForeignObjects(uow, input);
// Update the domain object
updateDomain(uow, input, domain, true);
// Build the outbound dto
AttachmentMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
// Print Debug Information for the output
if (log.isDebugEnabled())
log.debug("Output: " + output);
return output;
} catch (FrameworkException e) {
// If it is, then re-throw as ApplicationsExceptions, else throw the FrameworkException.
if (e.getCause() != null && e.getCause() instanceof ApplicationExceptions) {
throw (ApplicationExceptions) e.getCause();
} else if (e.getCause() != null && e.getCause() instanceof ApplicationException) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add((ApplicationException) e.getCause());
throw appExps;
} else
throw e;
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentMaintenanceTx method update.
// .//GEN-END:_prevalidateUpdate_1_be
// .//GEN-BEGIN:_update_1_be
/**
* Updates an existing instance of Attachment.
* @param input The new values for the domain object.
* @throws ApplicationExceptions This will be thrown if the input contains invalid data.
* @throws FrameworkException Indicates some system error.
* @return The object details.
*/
public AttachmentMaintenanceRetrieveOutDto update(AttachmentMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled())
log.debug("Input: " + input);
// create the UOW
uow = new UOW();
// Preprocess the input
preprocess(uow, input);
// Retrieve the object
Attachment domain = load(uow, input);
// Ensure the domain object has not been modified
domainObjectChangedTest(input.getPerformDirtyReadCheck(), domain, input.getLastChangedOn());
// Validate the foreign objects
validateForeignObjects(uow, input);
// Update the domain object
updateDomain(uow, input, domain, false);
uow.update(domain);
// Commit the changes
uow.commit();
// Print Debug Information for the output
if (log.isDebugEnabled())
log.debug("Successfully updated the domain object. Now retrieving the object details.");
// Build the outbound dto by performing a retrieve
AttachmentMaintenanceRetrieveInDto retrieveInDto = new AttachmentMaintenanceRetrieveInDto();
retrieveInDto.setHeaderDto(input.getHeaderDto());
retrieveInDto.setAttachmentId(input.getAttachmentId());
AttachmentMaintenanceRetrieveOutDto output = retrieve(retrieveInDto);
return output;
} catch (FrameworkException e) {
// If it is, then re-throw as ApplicationsExceptions, else throw the FrameworkException.
if (e.getCause() != null && e.getCause() instanceof ApplicationExceptions) {
throw (ApplicationExceptions) e.getCause();
} else if (e.getCause() != null && e.getCause() instanceof ApplicationException) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add((ApplicationException) e.getCause());
throw appExps;
} else
throw e;
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class JDBCAppenderWithAttachmentTest method testJAXBAttachment.
/**
* Tests the logging of an INFO message along with a domain object attachment (has JAXB annotations).
*/
public void testJAXBAttachment() throws Exception {
String correlationType = "testJAXBAttachment";
Attachment data = new Attachment();
data.setRemarks("An example domain object");
String logId = null;
try {
createMDC(correlationType);
MDC.put(AttachmentMeta.DATA, data);
log.info("test attachment");
m_connection = AbstractDataWrapper.getConnection();
m_stmt = m_connection.createStatement();
m_rs = m_stmt.executeQuery("select * from " + BUSINESS_EVENT_LOGS + " where CORRELATION_TYPE='" + correlationType + '\'');
assertTrue("Query on " + BUSINESS_EVENT_LOGS + " should have returned a ResultSet", m_rs.next());
logId = m_rs.getString("LOG_ID");
assertEquals(correlationType, m_rs.getString("CORRELATION_TYPE"));
assertEquals("CK1", m_rs.getString("CORRELATION_KEY1"));
assertEquals("CK2", m_rs.getString("CORRELATION_KEY2"));
assertEquals("CK3", m_rs.getString("CORRELATION_KEY3"));
assertEquals("STI", m_rs.getString("SCHEDULED_TASK_ID"));
assertEquals("MI", m_rs.getString("MESSAGE_ID"));
assertNotNull("Logged On value should be present", m_rs.getTimestamp("LOGGED_ON"));
assertEquals("LB", m_rs.getString("LOGGED_BY"));
assertEquals("PN", m_rs.getString("PROCESS_NAME"));
assertEquals("SPN", m_rs.getString("SUB_PROCESS_NAME"));
assertEquals("INFO", m_rs.getString("MESSAGE_TYPE"));
assertEquals("test attachment", m_rs.getString("MESSAGE_TEXT"));
assertEquals(JDBCAppenderWithAttachmentTest.class.getName(), m_rs.getString("SOURCE_CLASS"));
assertNull(m_rs.getString("SOURCE_METHOD"));
assertNull(m_rs.getString("SOURCE_LINE"));
assertTrue(m_rs.getString("STACK_TRACE") == null || m_rs.getString("STACK_TRACE").trim().length() == 0);
assertFalse("Query on " + BUSINESS_EVENT_LOGS + " should have returned only one ResultSet", m_rs.next());
m_stmt.close();
m_connection.close();
// Check the attachment
m_connection = AbstractDataWrapper.getConnection();
m_stmt = m_connection.createStatement();
m_rs = m_stmt.executeQuery("select * from " + ATTACHMENTS + " where SERIALIZED_KEY='" + generateSerializedKey(logId) + '\'');
assertTrue("Query on " + ATTACHMENTS + " should have returned a ResultSet", m_rs.next());
assertEquals(generateSerializedKey(logId), m_rs.getString("SERIALIZED_KEY"));
assertEquals(data.getClass().getName(), m_rs.getString("ORIGINAL_FILE_NAME"));
assertEquals("E", m_rs.getString("ATTACHMENT_TYPE"));
assertEquals(AttachmentService.CONTENT_TYPE_JAXB, m_rs.getString("CONTENT_TYPE"));
assertNull(m_rs.getString("DESCRIPTION"));
assertNull(m_rs.getString("REMARKS"));
assertNull(m_rs.getString("SUPERCEDED_BY"));
assertNotNull(m_rs.getTimestamp("CREATED_ON"));
assertNull(m_rs.getString("CREATED_BY"));
assertNull(m_rs.getTimestamp("LAST_CHANGED_ON"));
assertNull(m_rs.getString("LAST_CHANGED_BY"));
assertTrue(new String(m_rs.getBytes("DATA")).indexOf(data.getRemarks()) > -1);
assertFalse("Query on " + ATTACHMENTS + " should have returned only one ResultSet", m_rs.next());
m_stmt.close();
m_connection.close();
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
} finally {
clearAttachments(logId);
clearLogs(correlationType);
}
}
use of org.jaffa.components.attachment.domain.Attachment in project jaffa-framework by jaffa-projects.
the class AttachmentHandler method endBeanDelete.
public void endBeanDelete(String path, Object source, Object target) throws ApplicationException, ApplicationExceptions, FrameworkException {
if (source instanceof AttachmentGraph && target instanceof Attachment) {
AttachmentGraph attachmentGraph = (AttachmentGraph) source;
Attachment attachment = (Attachment) target;
IAttachmentData attachmentDataImpl = AttachmentFactory.getAttachmentDataImpl();
if (attachmentDataImpl != null && attachment.getDocumentReferenceId() != null) {
Criteria c = new Criteria();
c.setTable(AttachmentMeta.getName());
c.addCriteria(AttachmentMeta.DOCUMENT_REFERENCE_ID, attachment.getDocumentReferenceId());
c.addCriteria(AttachmentMeta.ATTACHMENT_ID, Criteria.RELATIONAL_NOT_EQUALS, attachment.getAttachmentId());
c.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Iterator<Attachment> iterator = attachment.getUOW().query(c).iterator();
if (iterator.hasNext()) {
Number count = (Number) ((Map) iterator.next()).get(Criteria.ID_FUNCTION_COUNT);
if (count == null || count.intValue() == 0) {
attachmentDataImpl.delete(attachment.getDocumentReferenceId());
}
}
}
}
}
Aggregations