use of com.googlecode.objectify.VoidWork in project activityinfo by bedatadriven.
the class HrdCatalogTest method enumWithNoChoices.
@Test
public void enumWithNoChoices() {
final ResourceId formId = ResourceId.generateId();
ResourceId villageField = ResourceId.valueOf("FV");
final ResourceId selectField = ResourceId.valueOf("FC");
FormClass formClass = new FormClass(formId);
formClass.setParentFormId(ResourceId.valueOf("foo"));
formClass.setLabel("NFI Distributions");
formClass.addField(villageField).setLabel("Village name").setCode("VILLAGE").setType(TextType.SIMPLE);
formClass.addField(selectField).setLabel("Favorite color").setType(new EnumType(Cardinality.SINGLE, EnumType.Presentation.AUTOMATIC, Collections.<EnumItem>emptyList()));
HrdStorageProvider catalog = new HrdStorageProvider();
catalog.create(formClass);
// Avoid cache
// objectifyCloseable.close();
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
HrdStorageProvider catalog = new HrdStorageProvider();
Optional<FormStorage> storage = catalog.getForm(formId);
FormClass deserializedSchema = storage.get().getFormClass();
}
});
}
use of com.googlecode.objectify.VoidWork in project teammates by TEAMMATES.
the class FeedbackSessionsDb method addStudentRespondents.
// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void addStudentRespondents(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.getRespondingStudentList().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 deleteInstructorRespondent.
// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void deleteInstructorRespondent(String email, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
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.getRespondingInstructorList().remove(email);
saveEntity(fs, feedbackSession);
}
});
} catch (RuntimeException e) {
if (e.getCause() instanceof EntityDoesNotExistException) {
throw (EntityDoesNotExistException) e.getCause();
}
throw e;
}
}
Aggregations