Search in sources :

Example 1 with MySqlStorageProvider

use of org.activityinfo.store.mysql.MySqlStorageProvider in project activityinfo by bedatadriven.

the class CloneDatabaseHandler method copySubForm.

private FieldType copySubForm(SubFormReferenceType subFormType) {
    ResourceId oldSubFormId = subFormType.getClassId();
    ResourceId newSubFormId = ResourceId.generateId();
    typeIdMapping.put(oldSubFormId, newSubFormId);
    FormClass targetFormClass = copyFormClass(oldSubFormId, newSubFormId);
    MySqlStorageProvider mysqlStorage = (MySqlStorageProvider) this.formCatalog.get();
    mysqlStorage.createOrUpdateFormSchema(targetFormClass);
    return new SubFormReferenceType(newSubFormId);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ResourceId(org.activityinfo.model.resource.ResourceId) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 2 with MySqlStorageProvider

use of org.activityinfo.store.mysql.MySqlStorageProvider 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;
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) VoidWork(com.googlecode.objectify.VoidWork) FormClass(org.activityinfo.model.form.FormClass) ArrayList(java.util.ArrayList) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider) FormField(org.activityinfo.model.form.FormField)

Example 3 with MySqlStorageProvider

use of org.activityinfo.store.mysql.MySqlStorageProvider in project activityinfo by bedatadriven.

the class DatabaseResource method createFormFromXForm.

@POST
@Path("/forms")
@Consumes("application/xml")
public Response createFormFromXForm(@Context UriInfo uri, XForm xForm) {
    UserDatabaseDTOWithForms schema = getSchema();
    LocationTypeDTO locationType = schema.getCountry().getNullLocationType();
    ActivityFormDTO activityDTO = new ActivityFormDTO();
    activityDTO.setName(xForm.getHead().getTitle());
    activityDTO.set("databaseId", databaseId);
    activityDTO.set("locationTypeId", locationType.getId());
    CreateResult createResult = dispatcher.execute(new CreateEntity(activityDTO));
    int activityId = createResult.getNewId();
    XFormReader builder = new XFormReader(xForm);
    FormClass formClass = builder.build();
    formClass.setId(CuidAdapter.activityFormClass(activityId));
    formClass.setDatabaseId(CuidAdapter.databaseId(databaseId));
    MySqlStorageProvider formCatalog = (MySqlStorageProvider) catalog.get();
    formCatalog.createOrUpdateFormSchema(formClass);
    return Response.created(uri.getAbsolutePathBuilder().path(RootResource.class).path("forms").path(formClass.getId().asString()).build()).build();
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) FormClass(org.activityinfo.model.form.FormClass) XFormReader(org.activityinfo.io.xform.XFormReader) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 4 with MySqlStorageProvider

use of org.activityinfo.store.mysql.MySqlStorageProvider in project activityinfo by bedatadriven.

the class ActivityInfoApiBackend method createNewForm.

@Override
public void createNewForm(FormClass formClass) {
    // Check that we have the permission to create in this database
    PermissionOracle permissionOracle = injector.getInstance(PermissionOracle.class);
    permissionOracle.assertDesignPrivileges(formClass, getAuthenticatedUser());
    ((MySqlStorageProvider) getStorage()).createOrUpdateFormSchema(formClass);
}
Also used : PermissionOracle(org.activityinfo.server.command.handler.PermissionOracle) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 5 with MySqlStorageProvider

use of org.activityinfo.store.mysql.MySqlStorageProvider in project activityinfo by bedatadriven.

the class ActivityInfoClientAsyncStub method updateFormSchema.

@Override
public Promise<Void> updateFormSchema(String formId, FormClass updatedSchema) {
    FormStorageProvider catalog = newCatalog();
    try {
        EntityTransaction tx = entityManager.get().getTransaction();
        tx.begin();
        Optional<FormStorage> collection = catalog.getForm(updatedSchema.getId());
        if (collection.isPresent()) {
            collection.get().updateFormClass(updatedSchema);
        } else {
            ((MySqlStorageProvider) catalog).createOrUpdateFormSchema(updatedSchema);
        }
        tx.commit();
        return Promise.resolved(null);
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) EntityTransaction(javax.persistence.EntityTransaction) FormStorage(org.activityinfo.store.spi.FormStorage) HrdFormStorage(org.activityinfo.store.hrd.HrdFormStorage) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Aggregations

MySqlStorageProvider (org.activityinfo.store.mysql.MySqlStorageProvider)5 FormClass (org.activityinfo.model.form.FormClass)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 FormStorage (org.activityinfo.store.spi.FormStorage)2 VoidWork (com.googlecode.objectify.VoidWork)1 ArrayList (java.util.ArrayList)1 EntityTransaction (javax.persistence.EntityTransaction)1 XFormReader (org.activityinfo.io.xform.XFormReader)1 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 FormField (org.activityinfo.model.form.FormField)1 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 PermissionOracle (org.activityinfo.server.command.handler.PermissionOracle)1 HrdFormStorage (org.activityinfo.store.hrd.HrdFormStorage)1 FormStorageProvider (org.activityinfo.store.spi.FormStorageProvider)1