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);
}
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;
}
}
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();
}
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);
}
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);
}
}
Aggregations