Skip to content

Instantly share code, notes, and snippets.

@shankybnl
Created June 6, 2018 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankybnl/bd739d15d0e35c165d0e48103b06e3b2 to your computer and use it in GitHub Desktop.
Save shankybnl/bd739d15d0e35c165d0e48103b06e3b2 to your computer and use it in GitHub Desktop.
PilotSteps.java
@Given("^Vehicle of pilot (\\d+) gets \"([^\"]*)\" by (\\d+) minutes")
public void vehicleOfPilotGetsByMinutes(long pilotId, String timeChange, int timeUpdateInMinutes) throws Throwable {
// Write code here that turns the phrase above into concrete actions
session = CrudOperations.createHibernateConnection();
List<PilotActivity> pilotActivity = session.createQuery("from PilotActivity where isActive=true order by id desc").setMaxResults(1).list();
DateTime currentExpectedStartTimeAtCreation = pilotActivity.get(0).getExpectedStartTimeAtCreation();
DateTime updatedStartTimeAtCreation;
if (timeChange.contains("delayed")) {
updatedStartTimeAtCreation = new DateTime(currentExpectedStartTimeAtCreation).plusMinutes(timeUpdateInMinutes);
} else {
updatedStartTimeAtCreation = new DateTime(currentExpectedStartTimeAtCreation).minusMinutes(timeUpdateInMinutes);
}
String updateExpectedStartTimeAtCreation = "update PilotActivity p set p.expectedStartTimeAtCreation = :updatedStartTimeAtCreation where p.pilotId = :pilotId";
query = session.createQuery(updateExpectedStartTimeAtCreation).setParameter("updatedStartTimeAtCreation", updatedStartTimeAtCreation)
.setParameter("pilotId", pilotId);
int result = query.executeUpdate();
LogUtil.info(result + " rows updated successfully");
CrudOperations.commitAndCloseHibernateConnection();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment