Search in sources :

Example 6 with VoidWork

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();
        }
    });
}
Also used : Optional(com.google.common.base.Optional) ResourceId(org.activityinfo.model.resource.ResourceId) VoidWork(com.googlecode.objectify.VoidWork) FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 7 with VoidWork

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;
    }
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) VoidWork(com.googlecode.objectify.VoidWork) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 8 with VoidWork

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;
    }
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) VoidWork(com.googlecode.objectify.VoidWork) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

VoidWork (com.googlecode.objectify.VoidWork)8 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)4 FeedbackSession (teammates.storage.entity.FeedbackSession)4 FormClass (org.activityinfo.model.form.FormClass)2 Test (org.junit.Test)2 Queue (com.google.appengine.api.taskqueue.Queue)1 Optional (com.google.common.base.Optional)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 JsonValue (org.activityinfo.json.JsonValue)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)1 TableModel (org.activityinfo.model.analysis.TableModel)1 FormField (org.activityinfo.model.form.FormField)1 ExportFormJob (org.activityinfo.model.job.ExportFormJob)1 JobRequest (org.activityinfo.model.job.JobRequest)1 JobStatus (org.activityinfo.model.job.JobStatus)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)1