mirror of
https://github.com/atlanticbiomedical/portal.git
synced 2025-07-01 10:07:27 -04:00
Modified calendar enteries to add extra fields.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ war/*.log
|
||||
*.class
|
||||
biomed.war
|
||||
gwt-unitCache/
|
||||
.gwt/
|
File diff suppressed because one or more lines are too long
@ -30,6 +30,7 @@ import com.google.common.collect.Maps;
|
||||
public class CalendarApi {
|
||||
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
|
||||
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
|
||||
private static final String API_ACCOUNT = "api@atlanticbiomedical.com";
|
||||
private static final String CLIENT_ID = "333768673996-904fuljpb428q9r37m2uujislhal5kt9.apps.googleusercontent.com";
|
||||
private static final String CLIENT_SECRET = "PAmHruqVbAXzEnnTwelx-Ll7";
|
||||
private static final String REFRESH_TOKEN = "1/fWvZebnDAhY0MlgK1IImcrGIDm4ZlILiRM8_47HsUFc";
|
||||
@ -66,8 +67,8 @@ public class CalendarApi {
|
||||
|
||||
Calendar calendar = buildCalendar();
|
||||
try {
|
||||
Event resultEvent = calendar.events()
|
||||
.insert("api@atlanticbiomedical.com", event).execute();
|
||||
Event resultEvent = calendar.events().insert(API_ACCOUNT, event)
|
||||
.execute();
|
||||
return resultEvent.getId();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -83,8 +84,7 @@ public class CalendarApi {
|
||||
Calendar calendar = buildCalendar();
|
||||
|
||||
try {
|
||||
Event event = calendar.events()
|
||||
.get("api@atlanticbiomedical.com", eventId).execute();
|
||||
Event event = calendar.events().get(API_ACCOUNT, eventId).execute();
|
||||
|
||||
EventAttendee attendee = new EventAttendee();
|
||||
attendee.setEmail(email);
|
||||
@ -97,8 +97,7 @@ public class CalendarApi {
|
||||
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC"));
|
||||
event.setEnd(new EventDateTime().setDateTime(end));
|
||||
|
||||
calendar.events().update("api@atlanticbiomedical.com", eventId, event)
|
||||
.execute();
|
||||
calendar.events().update(API_ACCOUNT, eventId, event).execute();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -112,7 +111,7 @@ public class CalendarApi {
|
||||
Calendar calendar = buildCalendar();
|
||||
|
||||
try {
|
||||
calendar.events().delete("api@atlanticbiomedical.com", eventId).execute();
|
||||
calendar.events().delete(API_ACCOUNT, eventId).execute();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -9,9 +9,10 @@ import com.biomed.shared.dispatch.DispatchService;
|
||||
import com.biomed.shared.dispatch.DispatchResult;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Singleton
|
||||
public class DispatchServiceServlet extends RemoteServiceServlet implements DispatchService {
|
||||
private final Dispatch dispatch;
|
||||
private final Dispatch dispatch;
|
||||
|
||||
@Inject
|
||||
public DispatchServiceServlet(Dispatch dispatch) {
|
||||
|
@ -16,97 +16,156 @@ import com.biomed.shared.api.EmptyResult;
|
||||
import com.biomed.shared.api.ScheduleAction;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
public class ScheduleHandler implements ActionHandler<ScheduleAction, EmptyResult> {
|
||||
public class ScheduleHandler implements
|
||||
ActionHandler<ScheduleAction, EmptyResult> {
|
||||
|
||||
private static final String QUERY =
|
||||
"INSERT INTO workorder " +
|
||||
"(job_date, client_id, tech, job_start, job_end, reason, remarks, job_status_id, job_scheduled_date, caller)" +
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String QUERY = "INSERT INTO workorder "
|
||||
+ "(job_date, client_id, tech, job_start, job_end, reason, remarks, job_status_id, job_scheduled_date, caller)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
private static final String FETCH_DATA_QUERY =
|
||||
"SELECT u.email, c.client_name, c.address, c.city, c.state, c.zip FROM user AS u, client AS c WHERE u.id = ? AND c.id = ?";
|
||||
private static final String FETCH_DATA_QUERY = "SELECT u.email, c.client_name, c.client_identification, c.address, c.address_2, c.city, c.state, c.zip, c.phone FROM user AS u, client AS c WHERE u.id = ? AND c.id = ?";
|
||||
|
||||
private static final String UPDATE_EVENT_ID_QUERY =
|
||||
"UPDATE workorder SET google_event_id = ? WHERE id = ?";
|
||||
private static final String UPDATE_EVENT_ID_QUERY = "UPDATE workorder SET google_event_id = ? WHERE id = ?";
|
||||
|
||||
@Override
|
||||
public Class<ScheduleAction> getType() {
|
||||
return ScheduleAction.class;
|
||||
}
|
||||
@Override
|
||||
public Class<ScheduleAction> getType() {
|
||||
return ScheduleAction.class;
|
||||
}
|
||||
|
||||
@Inject
|
||||
Provider<Connection> connectionProvider;
|
||||
@Inject
|
||||
Provider<Connection> connectionProvider;
|
||||
|
||||
@Inject
|
||||
CalendarApi calendarApi;
|
||||
@Inject
|
||||
CalendarApi calendarApi;
|
||||
|
||||
@Override
|
||||
public EmptyResult execute(ScheduleAction action, ExecutionContext context) throws Exception {
|
||||
Connection connection = connectionProvider.get();
|
||||
@Override
|
||||
public EmptyResult execute(ScheduleAction action, ExecutionContext context)
|
||||
throws Exception {
|
||||
Connection connection = connectionProvider.get();
|
||||
|
||||
int workorderId = insertWorkorder(connection, action);
|
||||
String eventId = updateGoogleCalendar(connection, action);
|
||||
updateGoogleEventId(connection, workorderId, eventId);
|
||||
int workorderId = insertWorkorder(connection, action);
|
||||
String eventId = updateGoogleCalendar(connection, action);
|
||||
updateGoogleEventId(connection, workorderId, eventId);
|
||||
|
||||
connection.close();
|
||||
connection.close();
|
||||
|
||||
return new EmptyResult();
|
||||
}
|
||||
return new EmptyResult();
|
||||
}
|
||||
|
||||
private static int insertWorkorder(Connection connection, ScheduleAction action)
|
||||
throws SQLException {
|
||||
private static int insertWorkorder(Connection connection,
|
||||
ScheduleAction action) throws SQLException {
|
||||
|
||||
PreparedStatement query = connection.prepareStatement(QUERY,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
query.setString(1, SqlUtil.formatDate(action.getJobDate()));
|
||||
query.setInt(2, action.getClientId());
|
||||
query.setInt(3, action.getTechId());
|
||||
query.setInt(4, action.getStartTime().toInteger());
|
||||
query.setInt(5, action.getEndTime().toInteger());
|
||||
query.setInt(6, action.getReason().getId());
|
||||
query.setString(7, action.getRemarks());
|
||||
query.setInt(8, action.getStatus().getId());
|
||||
query.setString(9, SqlUtil.formatDate(new Date()));
|
||||
query.setString(10, action.getRequestedBy());
|
||||
query.execute();
|
||||
|
||||
PreparedStatement query = connection.prepareStatement(QUERY, Statement.RETURN_GENERATED_KEYS);
|
||||
query.setString(1, SqlUtil.formatDate(action.getJobDate()));
|
||||
query.setInt(2, action.getClientId());
|
||||
query.setInt(3, action.getTechId());
|
||||
query.setInt(4, action.getStartTime().toInteger());
|
||||
query.setInt(5, action.getEndTime().toInteger());
|
||||
query.setInt(6, action.getReason().getId());
|
||||
query.setString(7, action.getRemarks());
|
||||
query.setInt(8, action.getStatus().getId());
|
||||
query.setString(9, SqlUtil.formatDate(new Date()));
|
||||
query.setString(10, action.getRequestedBy());
|
||||
query.execute();
|
||||
ResultSet keys = query.getGeneratedKeys();
|
||||
if (keys.next()) {
|
||||
return keys.getInt(1);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ResultSet keys = query.getGeneratedKeys();
|
||||
if (keys.next()) {
|
||||
return keys.getInt(1);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
private String updateGoogleCalendar(Connection connection,
|
||||
ScheduleAction action) throws SQLException {
|
||||
Date startDate = action.getStartTime().toDate(action.getJobDate());
|
||||
Date endDate = action.getEndTime().toDate(action.getJobDate());
|
||||
|
||||
private String updateGoogleCalendar(Connection connection, ScheduleAction action)
|
||||
throws SQLException {
|
||||
Date startDate = action.getStartTime().toDate(action.getJobDate());
|
||||
Date endDate = action.getEndTime().toDate(action.getJobDate());
|
||||
PreparedStatement query2 = connection.prepareStatement(FETCH_DATA_QUERY);
|
||||
query2.setInt(1, action.getTechId());
|
||||
query2.setInt(2, action.getClientId());
|
||||
query2.execute();
|
||||
|
||||
PreparedStatement query2 = connection.prepareStatement(FETCH_DATA_QUERY);
|
||||
query2.setInt(1, action.getTechId());
|
||||
query2.setInt(2, action.getClientId());
|
||||
query2.execute();
|
||||
ResultSet results = query2.getResultSet();
|
||||
results.first();
|
||||
|
||||
ResultSet results = query2.getResultSet();
|
||||
results.first();
|
||||
String email = results.getString("email");
|
||||
String summary = results.getString("client_name");
|
||||
|
||||
String location = formatLocation(results);
|
||||
String description = formatDescription(results, action);
|
||||
|
||||
return calendarApi.scheduleEvent(email, startDate, endDate, summary,
|
||||
description, location);
|
||||
}
|
||||
|
||||
String email = results.getString("email");
|
||||
String summary = results.getString("client_name");
|
||||
String location = results.getString("address") + " " + results.getString("city") + " " + results.getString("city") + " " + results.getString("state") + " " + results.getString("zip");
|
||||
String description = action.getReason().getLabel() + "\n" + action.getRequestedBy() + "\n" + action.getRemarks() + "\n" + action.getStatus().getLabel();
|
||||
private String formatLocation(ResultSet results) throws SQLException {
|
||||
String address = results.getString("address");
|
||||
String address2 = results.getString("address_2");
|
||||
String city = results.getString("city");
|
||||
String state = results.getString("state");
|
||||
String zip = results.getString("zip");
|
||||
|
||||
return calendarApi.scheduleEvent(email, startDate, endDate, summary, description, location);
|
||||
}
|
||||
if (address2 != null) {
|
||||
return String.format("%s %s, %s, %s. %s", address, address2, city, state, zip);
|
||||
} else {
|
||||
return String.format("%s, %s, %s. %s", address, city, state, zip);
|
||||
}
|
||||
}
|
||||
|
||||
private String formatDescription(ResultSet results, ScheduleAction action) throws SQLException {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
private static void updateGoogleEventId(Connection connection, int workorderId, String eventId)
|
||||
throws SQLException {
|
||||
String address2 = results.getString("address_2");
|
||||
|
||||
builder
|
||||
.append("Customer:\n")
|
||||
.append("\t").append(results.getString("client_identification")).append("\n\n")
|
||||
.append("Phone:\n")
|
||||
.append("\t").append(results.getString("phone")).append("\n\n")
|
||||
.append("Address:\n")
|
||||
.append("\t").append(results.getString("address")).append("\n");
|
||||
|
||||
PreparedStatement query = connection.prepareStatement(UPDATE_EVENT_ID_QUERY);
|
||||
query.setString(1, eventId);
|
||||
query.setInt(2, workorderId);
|
||||
if (address2 != null) {
|
||||
builder.append("\t").append(address2).append("\n");
|
||||
}
|
||||
|
||||
builder
|
||||
.append("\t").append(results.getString("city"))
|
||||
.append(", ").append(results.getString("state"))
|
||||
.append(". ").append(results.getString("zip"))
|
||||
.append("\n\n");
|
||||
|
||||
if (action.getRequestedBy() != null) {
|
||||
builder.append("Requested By:\n")
|
||||
.append("\t").append(action.getRequestedBy()).append("\n\n");
|
||||
}
|
||||
|
||||
query.execute();
|
||||
}
|
||||
builder
|
||||
.append("Reason:\n")
|
||||
.append("\t").append(action.getReason().getLabel()).append("\n\n")
|
||||
.append("Status:\n")
|
||||
.append("\t").append(action.getStatus().getLabel()).append("\n\n");
|
||||
|
||||
if (action.getRemarks() != null) {
|
||||
builder.append("Remarks:\n")
|
||||
.append("\t").append(action.getRemarks()).append("\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void updateGoogleEventId(Connection connection,
|
||||
int workorderId, String eventId) throws SQLException {
|
||||
|
||||
PreparedStatement query = connection
|
||||
.prepareStatement(UPDATE_EVENT_ID_QUERY);
|
||||
query.setString(1, eventId);
|
||||
query.setInt(2, workorderId);
|
||||
|
||||
query.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user