Search in sources :

Example 36 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class PatternGenerator method getContextWithData.

/**
 * Combines data from the metadata file to data from the WM's context,
 * and returns the combined context.
 * @return the combined context from WM and the metadata
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 * @throws PatternGeneratorException
 */
private Context getContextWithData() throws ParserConfigurationException, SAXException, IOException, PatternGeneratorException {
    // parse the metaData.. Force XML validation
    Map metaDataMap = DomParser.parse(m_patternMetaData.getFile(), true);
    // strip off the root element from the metaDataMap
    metaDataMap = stripRoot(metaDataMap);
    if (metaDataMap == null) {
        throw new PatternGeneratorException("PatternMetaData file " + m_patternMetaData.getFile() + " is incorrectly formatted");
    }
    // copy metaDataMap to context
    Context context = m_wm.getContext();
    for (Object entries : metaDataMap.entrySet()) {
        Map.Entry entry = (Map.Entry) entries;
        context.put(entry.getKey(), entry.getValue());
    }
    // Add some static data to the context
    context.put(XML_DATE_TIME, new DateTime());
    context.put(PROPERTY_PROJECT_ROOT_DIRECTORY, m_pgProperties.getProperty(PROPERTY_PROJECT_ROOT_DIRECTORY));
    context.put(PROPERTY_JAVA_ROOT_DIRECTORY, m_pgProperties.getProperty(PROPERTY_JAVA_ROOT_DIRECTORY));
    context.put(PROPERTY_SQL_ROOT_DIRECTORY, m_pgProperties.getProperty(PROPERTY_SQL_ROOT_DIRECTORY));
    // This is used by the WM template to put temporary data in a scratchpad Map...
    context.put(XML_SCRATCHPAD_FOR_WM, new HashMap());
    // put an instance of this class into the context so methods can be
    // called to get table and column names
    context.put("PatternGenerator", this);
    return context;
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 37 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class PatternGenerator method generateTempFile.

// Generates tempFileName
// Modifies the input object context !!!
private String generateTempFile(String patternTemplate, String patternMetaData, Context context) throws IOException, WebMacroException {
    // write the Output to the temp folder using WebMacro
    String tempFileName = getAbsoluteFileName(m_pgProperties.getProperty(PROPERTY_TEMP_META_DIRECTORY), patternMetaData);
    writeWm(patternTemplate, context, tempFileName);
    // append to the audit.log
    String log = '\n' + new DateTime().toString() + " - Processing PatternTemplate: " + patternTemplate + " using PatternMetaData: " + patternMetaData + '\n' + "Created temporary file: " + tempFileName;
    writeMessage(m_auditFile, log, true);
    return tempFileName;
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 38 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class ExcelExportService method registerCustomDateMorpher.

/**
 * Registers a custom Morpher to handle, based on the input flag, either a DateTime or DateOnly class.
 */
private static void registerCustomDateMorpher(boolean dateTime) {
    final Class targetType = dateTime ? DateTime.class : DateOnly.class;
    Morpher targetMorpher = JSONUtils.getMorpherRegistry().getMorpherFor(targetType);
    if (targetMorpher == null || targetMorpher == IdentityObjectMorpher.getInstance()) {
        synchronized (JSONUtils.getMorpherRegistry()) {
            targetMorpher = JSONUtils.getMorpherRegistry().getMorpherFor(targetType);
            if (targetMorpher == null || targetMorpher == IdentityObjectMorpher.getInstance()) {
                // Create a custom Morpher
                targetMorpher = new ObjectMorpher() {

                    /**
                     * Returns the target Class (DateTime.class or DateOnly.class) for conversion.
                     */
                    public Class morphsTo() {
                        return targetType;
                    }

                    /**
                     * Returns true if the Morpher supports conversion from this Class. Only the String class is supported currently.
                     */
                    public boolean supports(Class clazz) {
                        return clazz == String.class;
                    }

                    /**
                     * Morphs the input object into an output object of the supported type.
                     */
                    public Object morph(Object value) {
                        try {
                            String layout = "yyyy-MM-dd'T'HH:mm:ss";
                            return targetType == DateTime.class ? Parser.parseDateTime((String) value, layout) : Parser.parseDateOnly((String) value, layout);
                        } catch (Exception e) {
                            if (log.isDebugEnabled())
                                log.debug("Error in converting '" + value + "' to " + (targetType == DateTime.class ? "DateTime" : "DateOnly"), e);
                            return value;
                        }
                    }
                };
                JSONUtils.getMorpherRegistry().registerMorpher(targetMorpher);
            }
        }
    }
}
Also used : Morpher(net.sf.ezmorph.Morpher) ObjectMorpher(net.sf.ezmorph.ObjectMorpher) IdentityObjectMorpher(net.sf.ezmorph.object.IdentityObjectMorpher) ObjectMorpher(net.sf.ezmorph.ObjectMorpher) IdentityObjectMorpher(net.sf.ezmorph.object.IdentityObjectMorpher) FlexClass(org.jaffa.flexfields.FlexClass) JSONObject(net.sf.json.JSONObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) DateTime(org.jaffa.datatypes.DateTime)

Example 39 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class TestConsumer method invoke.

public void invoke(UOW uow, TestMessageSingleton message) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Handling message " + message);
    }
    // Send an Email
    if (message.getEmailAddress() != null) {
        new EmailerBean().sendMail(new String[] { message.getEmailAddress() }, SUBJECT, "Jaffa Transaction Tester message - Time: " + new DateTime());
    }
    // Pause
    Thread.sleep(message.getDelay());
    // Perform DBQuery
    if (message.getDbQuery() > 0) {
        long count = message.getDbQuery();
        Criteria c = new Criteria();
        c.setTable(SOAEventMeta.getName());
        for (int p = 0; p < count; p++) {
            uow.query(c);
        }
    }
    // Fail the transaction
    if (message.isFail())
        throw new ApplicationException("jaffa.tester.TestConsumer.fail");
}
Also used : ApplicationException(org.jaffa.exceptions.ApplicationException) EmailerBean(org.jaffa.util.EmailerBean) Criteria(org.jaffa.persistence.Criteria) DateTime(org.jaffa.datatypes.DateTime)

Example 40 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class RaiseEventService method raiseSoaEvent.

// TODO-SWAT add script events here
public void raiseSoaEvent(UOW uow, String eventName, String description, String category, List<HeaderParam> headerParams) throws FrameworkException, ApplicationExceptions {
    // there too.
    if (!SOAEventEnabledConfigurationFactory.instance().isEnabled(eventName)) {
        if (log.isDebugEnabled())
            log.debug("SOA event disabled: " + eventName);
        return;
    }
    UOW localUow = null;
    try {
        if (uow == null || !uow.isActive()) {
            localUow = new UOW();
        }
        SOAEventQueueMessage message = new SOAEventQueueMessage();
        message.setEventName(eventName);
        message.setDescription(description);
        message.setCreatedOn(new DateTime());
        message.setCreatedBy(SecurityManager.getPrincipal() != null ? SecurityManager.getPrincipal().getName() : null);
        if (category != null) {
            message.setCategory(category);
        }
        if (headerParams != null && headerParams.size() > 0) {
            message.setHeaderParams(headerParams.toArray(new HeaderParam[0]));
        }
        if (log.isDebugEnabled()) {
            log.debug("Creating SoaEvent Message" + message);
        }
        if (localUow != null) {
            localUow.addMessage(message);
            localUow.commit();
        } else {
            uow.addMessage(message);
        }
    } finally {
        if (localUow != null && localUow.isActive()) {
            try {
                localUow.rollback();
            } catch (Exception e) {
                log.error(e);
            }
        }
    }
}
Also used : HeaderParam(org.jaffa.modules.messaging.services.HeaderParam) UOW(org.jaffa.persistence.UOW) DateTime(org.jaffa.datatypes.DateTime) FrameworkException(org.jaffa.exceptions.FrameworkException)

Aggregations

DateTime (org.jaffa.datatypes.DateTime)74 Criteria (org.jaffa.persistence.Criteria)16 UOW (org.jaffa.persistence.UOW)11 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)9 PreparedStatement (java.sql.PreparedStatement)8 ValidationException (org.jaffa.datatypes.ValidationException)8 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)8 Iterator (java.util.Iterator)7 Map (java.util.Map)5 Date (java.util.Date)4 FrameworkException (org.jaffa.exceptions.FrameworkException)4 LinkedHashMap (java.util.LinkedHashMap)3 JMSException (javax.jms.JMSException)3 MarshallException (org.directwebremoting.extend.MarshallException)3 CheckBoxModel (org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)3 DateTimeModel (org.jaffa.presentation.portlet.widgets.model.DateTimeModel)3 DropDownModel (org.jaffa.presentation.portlet.widgets.model.DropDownModel)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Enumeration (java.util.Enumeration)2 LinkedList (java.util.LinkedList)2