Example usage for java.time Instant now

List of usage examples for java.time Instant now

Introduction

In this page you can find the example usage for java.time Instant now.

Prototype

public static Instant now() 

Source Link

Document

Obtains the current instant from the system clock.

Usage

From source file:io.syndesis.rest.v1.state.ClientSideState.java

static long currentTimestmpUtc() {
    return Instant.now().toEpochMilli() / 1000;
}

From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java

@Test
public void testDelete() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    VmApi vmApi = new VmApi(restClient);

    Task task = vmApi.delete("foo");
    assertEquals(task, responseTask);// www. j av  a 2s. c o m
}

From source file:com.orange.cepheus.broker.persistence.RegistrationsRepositoryTest.java

@Test
public void getRegistrationWithExceptionTest()
        throws URISyntaxException, RegistrationPersistenceException, EmptyResultDataAccessException {
    thrown.expect(RegistrationPersistenceException.class);
    Instant expirationDate = Instant.now().plus(1, ChronoUnit.DAYS);
    jdbcTemplate.update("insert into t_registrations(id,expirationDate,registerContext) values(?,?,?)", "12345",
            expirationDate.toString(), "aaaaaa");
    Registration foundRegistration = registrationsRepository.getRegistration("12345");
}

From source file:org.noorganization.instalist.server.api.ListResource.java

/**
 * Updates a existing list.//from w w w.  j  a  v  a  2s. c o  m
 * @param _groupId The id of the group containing the list.
 * @param _listUUID The uuid of the list to update.
 * @param _listInfo Information for changing the list. Not all information needs to be set.
 */
@PUT
@TokenSecured
@Path("{listuuid}")
@Consumes("application/json")
@Produces({ "application/json" })
public Response putList(@PathParam("groupid") int _groupId, @PathParam("listuuid") String _listUUID,
        ListInfo _listInfo) throws Exception {
    if ((_listInfo.getDeleted() != null && _listInfo.getDeleted())
            || (_listInfo.getName() != null && _listInfo.getName().length() == 0)
            || (_listInfo.getUUID() != null && !_listInfo.getUUID().equals(_listUUID)))
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA);

    UUID listUUID;
    UUID categoryUUID = null;
    boolean removeCategory = false;
    try {
        listUUID = UUID.fromString(_listUUID);
        if (_listInfo.getCategoryUUID() != null)
            categoryUUID = UUID.fromString(_listInfo.getCategoryUUID());
        else if (_listInfo.getRemoveCategory() != null && _listInfo.getRemoveCategory())
            removeCategory = true;
    } catch (IllegalArgumentException _e) {
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID);
    }
    Instant updated;
    Instant now = Instant.now();
    if (_listInfo.getLastChanged() != null) {
        updated = _listInfo.getLastChanged().toInstant();
        if (now.isBefore(updated))
            return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE);
    } else
        updated = now;

    EntityManager manager = DatabaseHelper.getInstance().getManager();
    IListController listController = ControllerFactory.getListController(manager);
    try {
        listController.update(_groupId, listUUID, _listInfo.getName(), categoryUUID, removeCategory, updated);
    } catch (ConflictException _e) {
        return ResponseFactory.generateConflict(
                new Error().withMessage("The new data is in " + "conflict with a saved list."));
    } catch (NotFoundException _e) {
        return ResponseFactory.generateNotFound(new Error().withMessage("The list was not " + "found."));
    } catch (GoneException _e) {
        return ResponseFactory.generateGone(new Error().withMessage("The list was " + "deleted already."));
    } catch (BadRequestException _e) {
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA);
    } finally {
        manager.close();
    }
    return ResponseFactory.generateOK(null);
}

From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java

@Test
public void testDelete() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    VmApi vmApi = new VmRestApi(restClient);

    Task task = vmApi.delete("foo");
    assertEquals(task, responseTask);//w  ww.j  a va2 s .c  om
}

From source file:org.basinmc.maven.plugins.minecraft.AbstractArtifactMojo.java

/**
 * Checks whether a snapshot artifact is considered valid.
 *///w  w  w  . ja  v a 2s.  co m
protected boolean isSnapshotArtifactValid(@Nonnull Artifact artifact, @Nullable Path path) {
    try {
        return !artifact.isSnapshot() || (path != null && Files.getLastModifiedTime(path).toInstant()
                .isAfter(Instant.now().minus(SNAPSHOT_CACHING_DURATION)));
    } catch (IOException ex) {
        this.getLog().warn("Could not verify state of snapshot artifact "
                + this.getArtifactCoordinateString(artifact) + ": " + ex.getMessage());
        return false;
    }
}

From source file:org.noorganization.instalist.server.api.EntryResource.java

/**
 * Updates an entry./* w  w w.  j  a  v  a 2s. c  o m*/
 * @param _groupId The id of the group containing the entry.
 * @param _entryUUID The uuid of the entry itself.
 * @param _entity Data for updating the entry.
 */
@PUT
@TokenSecured
@Path("{entryuuid}")
@Consumes("application/json")
@Produces({ "application/json" })
public Response putEntry(@PathParam("groupid") int _groupId, @PathParam("entryuuid") String _entryUUID,
        EntryInfo _entity) throws Exception {
    if ((_entity.getUUID() != null && !_entity.getUUID().equals(_entryUUID))
            || (_entity.getDeleted() != null && _entity.getDeleted())
            || (_entity.getAmount() != null && _entity.getAmount() < 0.001f))
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA);

    UUID toUpdate;
    UUID productUUID = null;
    UUID listUUID = null;
    try {
        toUpdate = UUID.fromString(_entryUUID);
        if (_entity.getProductUUID() != null)
            productUUID = UUID.fromString(_entity.getProductUUID());
        if (_entity.getListUUID() != null)
            listUUID = UUID.fromString(_entity.getListUUID());
    } catch (IllegalArgumentException _e) {
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID);
    }
    Instant updated;
    if (_entity.getLastChanged() != null) {
        updated = _entity.getLastChanged().toInstant();
        if (Instant.now().isBefore(updated))
            return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE);
    } else
        updated = Instant.now();

    EntityManager manager = DatabaseHelper.getInstance().getManager();
    IEntryController entryController = ControllerFactory.getEntryController(manager);
    try {
        entryController.update(_groupId, toUpdate, productUUID, listUUID, _entity.getAmount(),
                _entity.getPriority(), _entity.getStruck(), updated);
    } catch (NotFoundException _e) {
        return ResponseFactory.generateNotFound(new Error().withMessage("The entry was not " + "found."));
    } catch (GoneException _e) {
        return ResponseFactory.generateGone(new Error().withMessage("The entry has been " + "deleted."));
    } catch (ConflictException _e) {
        return ResponseFactory.generateConflict(
                new Error().withMessage("The sent data would " + "conflict with saved list entry."));
    } catch (BadRequestException _e) {
        return ResponseFactory.generateBadRequest(
                new Error().withMessage("The referenced " + "product or list was not found."));
    } finally {
        manager.close();
    }

    return ResponseFactory.generateOK(null);
}

From source file:cloudfoundry.norouter.f5.Agent.java

private void updatePoolMemberDescription(String poolName, RouteDetails route) {
    final Pool pool = client.getPool(poolName);
    pool.getMembers()/*from w w  w.  j  a  v a  2 s . c om*/
            .ifPresent(members -> members.stream()
                    .filter(member -> member.getName().equals(route.getAddress().toString())).findFirst()
                    .ifPresent(member -> {
                        final Optional<PoolMemberDescription> existingDescription = PoolMemberDescription
                                .fromJsonish(member.getDescription());
                        final PoolMemberDescription desiredDescription = new PoolMemberDescription(route);
                        boolean update = true;
                        if (existingDescription.isPresent()) {
                            final PoolMemberDescription description = existingDescription.get();
                            desiredDescription.setCreated(description.getCreated());
                            desiredDescription.setModified(description.getModified());
                            update = !desiredDescription.equals(description);
                        }
                        if (update) {
                            desiredDescription.setModified(Instant.now());
                            client.updatePoolMemberDescription(poolName, route.getAddress(),
                                    desiredDescription.toJsonish());
                        }
                    }));
}

From source file:com.github.aptd.simulation.elements.IBaseElement.java

@IAgentActionFilter
@IAgentActionName(name = "simtime/max")
private ZonedDateTime maxTime() {
    return ZonedDateTime.ofInstant(Instant.now().plus(Duration.ofDays(9999)), m_timezone);
}

From source file:org.noorganization.instalist.server.api.IngredientResource.java

/**
 * Updates an ingredient./*from   ww w .ja  v  a2 s  .  co  m*/
 * @param _groupId The id of the group containing the ingredient.
 * @param _ingredientUUID The uuid of the ingredient itself.
 * @param _entity Data for updating the ingredient.
 */
@PUT
@TokenSecured
@Path("{ingredientuuid}")
@Consumes("application/json")
@Produces({ "application/json" })
public Response putIngredient(@PathParam("groupid") int _groupId,
        @PathParam("ingredientuuid") String _ingredientUUID, IngredientInfo _entity) throws Exception {
    if ((_entity.getUUID() != null && !_entity.getUUID().equals(_ingredientUUID))
            || (_entity.getDeleted() != null && _entity.getDeleted())
            || (_entity.getAmount() != null && _entity.getAmount() < 0.001f))
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA);

    UUID toUpdate;
    UUID productUUID = null;
    UUID recipeUUID = null;
    try {
        toUpdate = UUID.fromString(_ingredientUUID);
        if (_entity.getProductUUID() != null)
            productUUID = UUID.fromString(_entity.getProductUUID());
        if (_entity.getRecipeUUID() != null)
            recipeUUID = UUID.fromString(_entity.getRecipeUUID());
    } catch (IllegalArgumentException _e) {
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID);
    }
    Instant updated;
    if (_entity.getLastChanged() != null) {
        updated = _entity.getLastChanged().toInstant();
        if (Instant.now().isBefore(updated))
            return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE);
    } else
        updated = Instant.now();

    EntityManager manager = DatabaseHelper.getInstance().getManager();
    IIngredientController ingredientController = ControllerFactory.getIngredientController(manager);
    try {
        ingredientController.update(_groupId, toUpdate, recipeUUID, productUUID, _entity.getAmount(), updated);
    } catch (NotFoundException _e) {
        return ResponseFactory.generateNotFound(new Error().withMessage("The ingredient was " + "not found."));
    } catch (GoneException _e) {
        return ResponseFactory.generateGone(new Error().withMessage("The ingredient has been " + "deleted."));
    } catch (ConflictException _e) {
        return ResponseFactory.generateConflict(
                new Error().withMessage("The sent data would " + "conflict with saved ingredient."));
    } catch (BadRequestException _e) {
        return ResponseFactory.generateBadRequest(
                new Error().withMessage("The referenced " + "product or recipe was not found."));
    } finally {
        manager.close();
    }

    return ResponseFactory.generateOK(null);
}