use of com.googlecode.objectify.VoidWork in project activityinfo by bedatadriven.
the class FixSubForm method maybeFixForm.
private boolean maybeFixForm(final PrintWriter logger, MySqlQueryExecutor executor, ResourceId parentFormId) {
logger.println("Fixing " + parentFormId + "...");
final MySqlStorageProvider catalog = new MySqlStorageProvider(executor);
FormStorage parentForm = catalog.getForm(parentFormId).get();
final FormClass formClass = parentForm.getFormClass();
logger.println("Loaded activity " + parentForm.getFormClass().getLabel());
final List<FormField> updated = new ArrayList<>();
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
Hrd.ofy().transact(new VoidWork() {
@Override
public void vrun() {
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
if (maybeFixForm(logger, formClass, formField)) {
updated.add(formField);
}
}
}
}
});
}
});
logger.println("TX COMPLETED!");
if (!updated.isEmpty()) {
logger.println("Updating parent form schema...");
catalog.createOrUpdateFormSchema(formClass);
return true;
} else {
return false;
}
}
use of com.googlecode.objectify.VoidWork in project activityinfo by bedatadriven.
the class JobResourceTest method startJob.
@Test
public void startJob() {
final org.activityinfo.json.JsonParser parser = new org.activityinfo.json.JsonParser();
final Queue queue = QueueFactory.getDefaultQueue();
final AuthenticatedUser user = new AuthenticatedUser("XYZ", 1, "akbertram@gmail.com");
final JobResource resource = new JobResource(Providers.of(user), queue);
// First request starts the job
final String jobId = ObjectifyService.run(new Work<String>() {
@Override
public String run() {
TableModel tableModel = ImmutableTableModel.builder().formId(ResourceId.valueOf("FORM1")).build();
ExportFormJob exportForm = new ExportFormJob(tableModel);
JobRequest request = new JobRequest(exportForm, "en");
Response response = resource.start(request.toJsonObject().toJson());
JsonValue resultObject = parser.parse((String) response.getEntity());
JobStatus result = JobStatus.fromJson(resultObject);
assertThat(result.getState(), equalTo(JobState.STARTED));
return result.getId();
}
});
// Second request retrieves status
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
Response statusResponse = resource.get(jobId);
JsonValue statusObject = parser.parse(((String) statusResponse.getEntity()));
JobStatus status = JobStatus.fromJson(statusObject);
assertThat(status.getState(), equalTo(JobState.STARTED));
}
});
}
use of com.googlecode.objectify.VoidWork in project teammates by TEAMMATES.
the class FeedbackSessionsDb method addInstructorRespondents.
// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void addInstructorRespondents(List<String> emails, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, emails);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
try {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new RuntimeException(new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString()));
}
fs.getRespondingInstructorList().addAll(emails);
saveEntity(fs, feedbackSession);
}
});
} catch (RuntimeException e) {
if (e.getCause() instanceof EntityDoesNotExistException) {
throw (EntityDoesNotExistException) e.getCause();
}
throw e;
}
}
use of com.googlecode.objectify.VoidWork in project teammates by TEAMMATES.
the class FeedbackSessionsDb method deleteStudentRespondent.
// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void deleteStudentRespondent(String email, FeedbackSessionAttributes feedbackSession) throws EntityDoesNotExistException, InvalidParametersException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
try {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new RuntimeException(new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString()));
}
fs.getRespondingStudentList().remove(email);
saveEntity(fs, feedbackSession);
}
});
} catch (RuntimeException e) {
if (e.getCause() instanceof EntityDoesNotExistException) {
throw (EntityDoesNotExistException) e.getCause();
}
throw e;
}
}
use of com.googlecode.objectify.VoidWork in project activityinfo by bedatadriven.
the class JobTaskServlet method markFailed.
private void markFailed(final JobEntity jobEntity, Exception e) {
LOGGER.log(Level.SEVERE, "Job " + jobEntity.getType() + " failed: " + e.getMessage(), e);
JobStore.ofy().transact(new VoidWork() {
@Override
public void vrun() {
JobEntity updatedEntity = JobStore.getUserJob(JobStore.getWebSafeKeyString(jobEntity)).now();
if (updatedEntity.getState() != JobState.STARTED) {
return;
}
updatedEntity.setState(JobState.FAILED);
JobStore.ofy().save().entity(updatedEntity).now();
}
});
}
Aggregations