List of usage examples for org.joda.time Instant now
public static Instant now()
From source file:app.sunstreak.yourpisd.util.DateHelper.java
License:Open Source License
public static String timeSince(DateTime dt) { StringBuilder sb = new StringBuilder(); sb.append("Last updated "); Period pd = new Interval(dt.getMillis(), Instant.now().getMillis()).toPeriod(); if (pd.getDays() > 0) { sb.append(pd.getDays());/*from w w w . j a v a 2 s.c o m*/ return sb.append(" days ago").toString(); } if (pd.getHours() > 0) sb.append(pd.getHours() + "hours "); if (pd.getMinutes() > 0) { sb.append(pd.getMinutes() + " minutes"); return sb.append(" ago").toString(); } return sb.append("less than a minute ago").toString(); }
From source file:ca.intelliware.ihtsdo.mlds.web.rest.ApplicationResource.java
@RequestMapping(value = Routes.APPLICATION_APPROVE, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@RolesAllowed({ AuthoritiesConstants.STAFF, AuthoritiesConstants.ADMIN })
@Timed//from w ww .j a va2s. co m
public @ResponseBody ResponseEntity<Application> approveApplication(@PathVariable long applicationId,
@RequestBody String approvalStateString) throws CloneNotSupportedException {
//FIXME why cant this be the body type?
ApprovalState approvalState = ApprovalState.valueOf(approvalStateString);
Application application = applicationRepository.findOne(applicationId);
if (application == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
authorizationChecker.checkCanApproveApplication(application);
//FIXME should there be state transition validation?
application.setApprovalState(approvalState);
//FIXME add flags to approval state?
if (Objects.equal(approvalState, ApprovalState.APPROVED)
|| Objects.equal(approvalState, ApprovalState.REJECTED)) {
application.setCompletedAt(Instant.now());
}
Affiliate affiliate = findAffiliateByUsername(application.getUsername());
if (affiliate == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
if (Objects.equal(approvalState, ApprovalState.APPROVED)) {
AffiliateDetails affiliateDetails = (AffiliateDetails) application.getAffiliateDetails().clone();
affiliateDetailsResetter.detach(affiliateDetails);
affiliateDetails = affiliateDetailsRepository.save(affiliateDetails);
affiliate.setAffiliateDetails(affiliateDetails);
affiliateRepository.save(affiliate);
}
//FIXME MLDS-314 not sure where this code should be
if (Objects.equal(application.getApplicationType(), ApplicationType.PRIMARY)) {
StandingState newStandingState = null;
if (Objects.equal(application.getApprovalState(), ApprovalState.APPROVED)) {
// MLDS-902 When the authorizing user is a member (ie not IHTSDO) then the account standing
// state should transition to "In Good Standing"
if (authorizationChecker.isAdmin()) {
newStandingState = StandingState.PENDING_INVOICE;
} else {
newStandingState = StandingState.IN_GOOD_STANDING;
}
} else if (Objects.equal(application.getApprovalState(), ApprovalState.REJECTED)) {
newStandingState = StandingState.REJECTED;
}
if (Objects.equal(affiliate.getStandingState(), StandingState.APPLYING) && newStandingState != null) {
affiliate.setStandingState(newStandingState);
affiliateRepository.save(affiliate);
affiliateAuditEvents.logStandingStateChange(affiliate);
}
}
applicationRepository.save(application);
if (Objects.equal(approvalState, ApprovalState.APPROVED)) {
User user = userRepository.getUserByEmailIgnoreCase(application.getAffiliateDetails().getEmail());
applicationApprovedEmailSender.sendApplicationApprovalEmail(user, application.getMember().getKey(),
affiliate.getAffiliateId());
}
applicationAuditEvents.logApprovalStateChange(application);
return new ResponseEntity<Application>(application, HttpStatus.OK);
}
From source file:ca.intelliware.ihtsdo.mlds.web.rest.ApplicationResource.java
@Transactional
@RequestMapping(value = Routes.APPLICATION_REGISTRATION, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@RolesAllowed({ AuthoritiesConstants.USER })
@Timed/*from w w w.j ava 2 s. co m*/
public @ResponseBody ResponseEntity<Application> submitApplication(@PathVariable long applicationId,
@RequestBody JsonNode request) {
PrimaryApplication application = (PrimaryApplication) applicationRepository.findOne(applicationId);
if (application == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
application = saveApplicationFields(request, application);
authorizationChecker.checkCanAccessApplication(application);
// Mark application as submitted
if (Objects.equal(application.getApprovalState(), ApprovalState.CHANGE_REQUESTED)) {
application.setApprovalState(ApprovalState.RESUBMITTED);
} else if (Objects.equal(application.getApprovalState(), ApprovalState.NOT_SUBMITTED)) {
application.setApprovalState(ApprovalState.SUBMITTED);
} else {
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
application.setSubmittedAt(Instant.now());
applicationRepository.save(application);
Affiliate affiliate = application.getAffiliate();
affiliate.setCreator(application.getUsername());
affiliate.setApplication(application);
affiliate.setType(application.getType());
affiliate.setHomeMember(application.getMember());
{
AffiliateDetails affiliateDetails = (AffiliateDetails) application.getAffiliateDetails().clone();
affiliateDetailsResetter.detach(affiliateDetails);
affiliate.setAffiliateDetails(affiliateDetails);
}
affiliateRepository.save(affiliate);
applicationAuditEvents.logApprovalStateChange(application);
if (application.getCommercialUsage() != null
&& Objects.equal(application.getCommercialUsage().getState(), UsageReportState.NOT_SUBMITTED)) {
commercialUsageService.transitionCommercialUsageApproval(application.getCommercialUsage(),
UsageReportTransition.SUBMIT);
}
return new ResponseEntity<Application>(application, HttpStatus.OK);
}
From source file:ca.intelliware.ihtsdo.mlds.web.rest.MemberResource.java
private File updateFile(MultipartFile multipartFile, File existingFile) throws IOException { File newFile = new File(); if (existingFile != null) { entityManager.detach(existingFile); }/* www .j a v a2 s. c o m*/ Blob blob = blobHelper.createBlobFrom(multipartFile); newFile.setContent(blob); newFile.setCreator(sessionService.getUsernameOrNull()); newFile.setFilename(multipartFile.getOriginalFilename()); newFile.setMimetype(multipartFile.getContentType()); newFile.setLastUpdated(Instant.now()); fileRepository.save(newFile); return newFile; }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.networking.OslpChannelHandlerServer.java
License:Open Source License
private Oslp.Message handleRegisterDeviceRequest(final byte[] deviceUid, final byte[] sequenceNumber, final Oslp.RegisterDeviceRequest registerRequest) throws UnknownHostException { final InetAddress inetAddress = InetAddress.getByAddress(registerRequest.getIpAddress().toByteArray()); final String deviceType = registerRequest.getDeviceType().toString(); final boolean hasSchedule = registerRequest.getHasSchedule(); final String deviceIdentification = registerRequest.getDeviceIdentification(); // Send message to OSGP-CORE to save IP Address, device type and has // schedule values in OSGP-CORE database. this.deviceRegistrationService.sendDeviceRegisterRequest(inetAddress, deviceType, hasSchedule, deviceIdentification);/*from w ww . j a va 2s .c om*/ OslpDevice oslpDevice = this.oslpDeviceSettingsService .getDeviceByDeviceIdentification(registerRequest.getDeviceIdentification()); // Save the security related values in the OSLP database. oslpDevice.updateRegistrationData(deviceUid, registerRequest.getDeviceType().toString(), Integer.valueOf(registerRequest.getRandomDevice())); oslpDevice.setSequenceNumber(SequenceNumberUtils.convertByteArrayToInteger(sequenceNumber)); oslpDevice = this.oslpDeviceSettingsService.updateDevice(oslpDevice); // Return current date and time in UTC so the device can sync the clock. final Oslp.RegisterDeviceResponse.Builder responseBuilder = Oslp.RegisterDeviceResponse.newBuilder() .setStatus(Oslp.Status.OK).setCurrentTime(Instant.now().toString(format)) .setRandomDevice(registerRequest.getRandomDevice()) .setRandomPlatform(oslpDevice.getRandomPlatform()); // Return local time zone information of the platform. Devices can use // this to convert UTC times to local times. final LocationInfo.Builder locationInfo = LocationInfo.newBuilder(); locationInfo.setTimeOffset(this.timeZoneOffsetMinutes); // Get the GPS values from OSGP-CORE database. final GpsCoordinatesDto gpsCoordinates = this.deviceDataService .getGpsCoordinatesForDevice(deviceIdentification); // Add GPS information when available in meta data. if (gpsCoordinates != null && gpsCoordinates.getLatitude() != null && gpsCoordinates.getLongitude() != null) { final int latitude = (int) ((gpsCoordinates.getLatitude()) * 1000000); final int longitude = (int) ((gpsCoordinates.getLongitude()) * 1000000); locationInfo.setLatitude(latitude).setLongitude(longitude); } responseBuilder.setLocationInfo(locationInfo); return Oslp.Message.newBuilder().setRegisterDeviceResponse(responseBuilder.build()).build(); }
From source file:com.amazonaws.codepipeline.jenkinsplugin.AWSCodePipelineJobCredentialsProvider.java
License:Open Source License
@Override public AWSSessionCredentials getCredentials() { if (this.credentials == null || this.lastRefreshedInstant.isBefore(Instant.now().minus(CREDENTIALS_DURATION))) { refresh();// w w w . j a v a2 s. c om } return this.credentials; }
From source file:com.amazonaws.codepipeline.jenkinsplugin.AWSCodePipelineJobCredentialsProvider.java
License:Open Source License
@Override public synchronized void refresh() { final GetJobDetailsRequest getJobDetailsRequest = new GetJobDetailsRequest().withJobId(jobId); final GetJobDetailsResult getJobDetailsResult = codePipelineClient.getJobDetails(getJobDetailsRequest); final com.amazonaws.services.codepipeline.model.AWSSessionCredentials credentials = getJobDetailsResult .getJobDetails().getData().getArtifactCredentials(); this.lastRefreshedInstant = Instant.now(); this.credentials = new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()); }
From source file:com.cloudera.nav.plugin.examples.stetson.CustomLineageCreator.java
License:Apache License
protected StetsonExecution createExecution() { StetsonExecution exec = new StetsonExecution(plugin.getNamespace()); exec.setPigExecution(getPigExecutionId()); exec.setName("Stetson Execution"); exec.setDescription("I am a custom operation instance"); exec.setLink("http://hasthelargehadroncolliderdestroyedtheworldyet.com/"); exec.setStarted(Instant.now()); exec.setEnded((new Instant(Instant.now().toDate().getTime() + 10000))); return exec;/*from ww w . j av a2 s . c om*/ }
From source file:com.cloudera.nav.plugin.examples.stetson2.CustomLineageCreator2.java
License:Apache License
@Override protected StetsonExecution2 createExecution() { StetsonExecution2 exec = new StetsonExecution2(plugin.getNamespace()); exec.setPigExecution(getPigExecutionId()); exec.setName("Stetson Execution"); exec.setDescription("I am a custom operation instance"); exec.setLink("http://hasthelargehadroncolliderdestroyedtheworldyet.com/"); exec.setStarted(Instant.now()); exec.setEnded((new Instant(Instant.now().toDate().getTime() + 10000))); // Extend the previous stetson example by linking it to inputs and outputs String inputName = "StetsonInput"; // Stetson's name for the input dataset String outputName = "StetsonOutput"; // Stetson's name for the output data exec.addInput(inputName, getHdfsEntityId(getInputPath())); exec.addOutput(outputName, getHdfsEntityId(getOutputPath())); return exec;/*from www. j a v a2s . c o m*/ }
From source file:com.cloudera.nav.sdk.examples.lineage.CustomLineageCreator.java
License:Apache License
protected StetsonExecution createExecution() { StetsonExecution exec = new StetsonExecution(plugin.getNamespace()); exec.setPigExecution(getPigExecutionId()); exec.setName("Stetson Execution"); exec.setDescription("I am a custom operation instance"); exec.setLink("http://hasthelargehadroncolliderdestroyedtheworldyet.com/"); exec.setIndex(10);//from w w w . ja va 2 s .co m exec.setSteward("chang"); exec.setStarted(Instant.now()); exec.setEnded((new Instant(Instant.now().toDate().getTime() + 10000))); return exec; }