Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.claresco.tinman.sql.XapiAgentProfileSQLWriter.java

License:Open Source License

private void updateAgentProfile(String theDocument, int theDocumentID, int theAgentProfileID)
        throws SQLException, XapiSQLOperationProblemException {
    myDocumentWriter.updateDocument(theDocument, theDocumentID);

    DateTime theStoredTime = DateTime.now();
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    myUpdateStatement.setTimestamp(1, SQLUtility.getTimestamp(theStoredTime), cal);

    myUpdateStatement.setInt(2, theAgentProfileID);

    myUpdateStatement.executeUpdate();//  w  ww . j a va 2  s. co m
}

From source file:com.claresco.tinman.sql.XapiStatementSQLWriter.java

License:Open Source License

/**
 * /*w  w  w.  j ava 2  s.  c om*/
 * Description:
 *    Insert a new statement to the database
 * 
 * Params:
 *    theStatement : the Statement object
 */
protected int insertNewStatement(XapiStatement theStatement, boolean newActivityAllowed,
        boolean generateRandomID) throws SQLException, XapiDataIntegrityException {
    int theId = super.fetchId();

    this.myInsertStatement.setInt(1, theId);
    this.myInsertStatement.setInt(2, this.myActorWriter.insertNewActor(theStatement.getActor()));
    this.myInsertStatement.setInt(3, this.myVerbWriter.insertNewVerb(theStatement.getVerb()));
    this.myInsertStatement.setInt(4,
            this.myObjectWriter.insertNewObject(theStatement.getObject(), newActivityAllowed));
    this.myInsertStatement.setNull(5, Types.NUMERIC);
    this.myInsertStatement.setNull(6, Types.NUMERIC);
    this.myInsertStatement.setNull(7, Types.TIMESTAMP);
    this.myInsertStatement.setNull(8, Types.TIMESTAMP);
    this.myInsertStatement.setNull(9, Types.NUMERIC);
    this.myInsertStatement.setNull(10, Types.CHAR);
    this.myInsertStatement.setString(11, theStatement.getId());

    if (theStatement.hasResult()) {
        this.myInsertStatement.setInt(5, this.myResultWriter.insertNewResult(theStatement.getResult()));
    }

    if (theStatement.hasContext()) {
        this.myInsertStatement.setInt(6,
                this.myContextWriter.insertNewContext(theStatement.getContext(), newActivityAllowed));
    }

    // Set timestamp
    if (theStatement.hasTimeStamp()) {
        Timestamp theTimestamp = SQLUtility.getTimestamp(theStatement.getTimeStamp());
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        this.myInsertStatement.setTimestamp(7, theTimestamp, cal);
    }

    DateTime theStoredTime = DateTime.now();
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    this.myInsertStatement.setTimestamp(8, SQLUtility.getTimestamp(theStoredTime), cal);

    // Check if a statement with that UUID already exists in the database
    if (!generateRandomID) {
        if (myStatementReader.doesStatementExists(theStatement.getId())) {
            // If so, throw an error
            throw new XapiDuplicateStatementIDException("Statement with that UUID already exists");
        }
    } else {
        this.myInsertStatement.setString(11, UUID.randomUUID().toString());
    }

    // If the statement voids another statement
    if (theStatement.isVoiding()) {
        voidStatement(theStatement);
    }

    this.myInsertStatement.executeUpdate();

    return theId;
}

From source file:com.claresco.tinman.sql.XapiStateSQLWriter.java

License:Open Source License

/**
 * //from   www.java2  s  .c o  m
 * Definition:
 *   Insert new state. If the state with that statekey already exists,
 *   update it.
 *
 * Params:
 *
 *
 */
protected int insertState(XapiState theState)
        throws SQLException, XapiDataIntegrityException, XapiSQLOperationProblemException {
    int theStateID = myStateReader.retrieveIDByStatekey(theState);

    ResultSet myRS = myStateReader.getStateResultSet(theStateID);
    myRS.next();

    if (theStateID != -1) {
        myDocumentWriter.updateDocument(theState.getDocument(), myRS.getInt("documentid"));
        updateState(theState, theStateID);

        myRS.close();
        return theStateID;
    } else {
        int theID = super.fetchId();

        myInsertStatement.setInt(1, theID);

        // Check the true value!!!!
        myInsertStatement.setInt(2,
                myActivityWriter.insertActivity(new XapiActivity(theState.getActivityIRI()), true));
        myInsertStatement.setInt(3, myActorWriter.insertNewActor(theState.getActor()));
        myInsertStatement.setString(4, theState.getID());

        myInsertStatement.setNull(5, Types.CHAR);
        if (theState.hasRegistration()) {
            myInsertStatement.setString(5, theState.getRegistration().toString());
        }

        myInsertStatement.setInt(6, myDocumentWriter.insertNewDocument(theState.getDocument()));

        DateTime theStoredTime = DateTime.now();
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        myInsertStatement.setTimestamp(7, SQLUtility.getTimestamp(theStoredTime), cal);

        myInsertStatement.executeUpdate();

        myRS.close();

        return theID;
    }
}

From source file:com.clicktravel.cheddar.infrastructure.persistence.filestore.FileItem.java

License:Apache License

/**
 * Create a file item from any given string, assumes UTF-encoding
 *
 * @param filename the name of the file you want to create
 * @param contents the string in UTF-8 encoding
 *//*from ww w.  j  av  a2s  . c om*/
public FileItem(final String filename, final String contents) {
    this.filename = filename;
    this.contents = contents.getBytes(StandardCharsets.UTF_8);
    lastUpdatedTime = DateTime.now();
}

From source file:com.clicktravel.cheddar.infrastructure.persistence.filestore.FileItem.java

License:Apache License

public FileItem(final String filename, final InputStream inputStream, final DateTime lastUpdatedTime)
        throws IOException {
    if (inputStream == null) {
        throw new IllegalArgumentException("Input stream cannot be null");
    }/*from w ww.j av  a  2  s .  c o  m*/
    this.filename = filename;
    if (lastUpdatedTime == null) {
        this.lastUpdatedTime = DateTime.now();
    } else {
        this.lastUpdatedTime = lastUpdatedTime;
    }
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    int read = -1;
    final byte[] buf = new byte[1024 * 50];
    try {
        while ((read = inputStream.read(buf)) != -1) {
            bout.write(buf, 0, read);
        }
        contents = bout.toByteArray();
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.clicktravel.cheddar.infrastructure.persistence.filestore.FileItem.java

License:Apache License

public FileItem(final String filename, final File file) throws IOException {
    this(filename, new FileInputStream(file), DateTime.now());
}

From source file:com.clicktravel.cheddar.metrics.intercom.IntercomMetricCollector.java

License:Apache License

@Override
public void createUser(final MetricUser user) {
    final User intercomUser = getIntercomUser(user);
    intercomUser.setSignedUpAt(DateTime.now().getMillis() / 1000);
    try {/*from   www.  ja  v a  2  s.c  o  m*/
        User.create(intercomUser);
    } catch (final Exception e) {
        logger.debug("Error creating a Intercom user: " + intercomUser + " - " + e.getMessage());
    }
}

From source file:com.clicktravel.cheddar.metrics.intercom.IntercomMetricCollector.java

License:Apache License

@Override
public void sendMetric(final Metric metric) {
    if (metric == null) {
        return;/*from ww  w .  ja v  a  2 s.  c  o  m*/

    }

    try {
        final Event event = new Event().setEventName(metric.name()).setUserID(metric.userId())
                .setCreatedAt(DateTime.now().getMillis() / 1000);

        if (metric.metaData() != null) {
            for (final String key : metric.metaData().keySet()) {
                if (metric.metaData().get(key).getClass().equals(String.class)) {
                    event.putMetadata(key, (String) metric.metaData().get(key));
                } else if (metric.metaData().get(key).getClass().equals(boolean.class)
                        || metric.metaData().get(key).getClass().equals(Boolean.class)) {
                    event.putMetadata(key, (Boolean) metric.metaData().get(key));
                } else if (metric.metaData().get(key).getClass().equals(double.class)
                        || metric.metaData().get(key).getClass().equals(Double.class)) {
                    event.putMetadata(key, (Double) metric.metaData().get(key));
                } else if (metric.metaData().get(key).getClass().equals(float.class)
                        || metric.metaData().get(key).getClass().equals(Float.class)) {
                    event.putMetadata(key, (Float) metric.metaData().get(key));
                } else if (metric.metaData().get(key).getClass().equals(int.class)
                        || metric.metaData().get(key).getClass().equals(Integer.class)) {
                    event.putMetadata(key, (Integer) metric.metaData().get(key));
                } else if (metric.metaData().get(key).getClass().equals(long.class)
                        || metric.metaData().get(key).getClass().equals(Long.class)) {
                    event.putMetadata(key, (Long) metric.metaData().get(key));
                } else {
                    event.putMetadata(key, String.valueOf(metric.metaData().get(key)));
                }
            }
        }
        Event.create(event);
    } catch (final Exception e) {
        logger.debug("Failed to send metric via Intercom", e);
    }
}

From source file:com.clicktravel.infrastructure.persistence.aws.s3.S3FileStore.java

License:Apache License

@Override
public URL publicUrlForFilePath(final FilePath filePath) throws NonExistentItemException {
    return amazonS3Client.generatePresignedUrl(bucketNameForFilePath(filePath), filePath.filename(),
            DateTime.now().plusHours(1).toDate(), HttpMethod.GET);
}

From source file:com.cloudera.director.azure.compute.provider.CleanUpTask.java

License:Apache License

/**
 * Creates a CleanUpTask.//from   ww w  .ja v a  2 s  . co  m
 *
 * NOTE: This method assume the VM is properly created and the VM object contain all the info
 * needed for proper cleanup.
 * @param resourceGroup         Azure Resource Group name
 * @param vm                    VirtualMachine info
 * @param computeProviderHelper
 * @param isPublicIPConfigured  does the template define a public IP that should be cleaned up
 */
public CleanUpTask(String resourceGroup, VirtualMachine vm, AzureComputeProviderHelper computeProviderHelper,
        boolean isPublicIPConfigured, int azureOperationPollingTimeout) {
    this.resourceGroup = resourceGroup;
    this.vm = vm;
    this.computeProviderHelper = computeProviderHelper;
    this.isPublicIPConfigured = isPublicIPConfigured;
    this.startTime = DateTime.now();
    this.azureOperationPollingTimeout = azureOperationPollingTimeout;
}