use of org.kie.workbench.common.forms.migration.tool.Resource in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorWithUnsupportedFieldsTest method doInit.
@Override
protected void doInit() throws Exception {
List<FormMigrationSummary> summaries = new ArrayList<>();
initForm(form -> userForm = form, DATAOBJECTS_RESOURCES, USER_WITH_UNSUPPORTED_FIELDS, userFormPath);
summaries.add(new FormMigrationSummary(new Resource<>(userForm, userFormPath)));
context = new MigrationContext(workspaceProject, weldContainer, migrationServicesCDIWrapper, new RealSystemAccess(), summaries);
}
use of org.kie.workbench.common.forms.migration.tool.Resource in project kie-wb-common by kiegroup.
the class BPMNFormAdapter method doCreateFormDefinition.
@Override
protected void doCreateFormDefinition(FormModel formModel, FormMigrationSummary formSummary) {
Form originalForm = formSummary.getOriginalForm().get();
Set<DataHolder> objectDataHolders = originalForm.getHolders().stream().filter(dataHolder -> !dataHolder.getType().equals(FormsMigrationConstants.DATA_HOLDER_TYPE_BASIC)).collect(Collectors.toSet());
if (!objectDataHolders.isEmpty()) {
FieldTypeManager fieldTypeManager = FieldTypeManager.get();
objectDataHolders.forEach(dataHolder -> {
Set<Field> dataHolderFields = originalForm.getFieldsForDataHolder(dataHolder);
if (dataHolderFields.isEmpty()) {
return;
}
FormModel newFormModel = createModelForDO(dataHolder);
String formName = formSummary.getBaseFormName() + "-" + dataHolder.getUniqeId();
String formAssetName = formName + "." + FormsMigrationConstants.NEW_FOMRS_EXTENSION;
FormDefinition newFormDefinition = new FormDefinition(newFormModel);
newFormDefinition.setId(UIDGenerator.generateUID());
newFormDefinition.setName(formName);
migrateFields(dataHolderFields, newFormDefinition, formSummary);
dataHolderFields.forEach(field -> field.setMovedToForm(formName));
Path newFormPath = Paths.convert(formSummary.getOriginalForm().getPath()).getParent().resolve(formAssetName);
FormMigrationSummary extraSummary = new FormMigrationSummary(formSummary.getOriginalForm());
extraSummary.setBaseFormName(formName);
extraSummary.setNewFormResource(new Resource<>(newFormDefinition, Paths.convert(newFormPath)));
migrationContext.getExtraSummaries().add(extraSummary);
Field field = new Field();
field.setFieldType(fieldTypeManager.getTypeByCode(FieldTypeBuilder.SUBFORM));
field.setId(System.currentTimeMillis());
field.setFieldName(dataHolder.getUniqeId());
field.setInputBinding(dataHolder.getUniqeId());
field.setLabel(new HashMap<>());
field.getLabel().put(FormsMigrationConstants.DEFAULT_LANG, dataHolder.getUniqeId());
field.setPosition(originalForm.getFormFields().size() + 1000);
field.setForm(originalForm);
originalForm.getFormFields().add(field);
});
}
super.doCreateFormDefinition(formModel, formSummary);
}
use of org.kie.workbench.common.forms.migration.tool.Resource in project kie-wb-common by kiegroup.
the class AbstractMigrationStep method persist.
private void persist(MigrationContext migrationContext) {
FormSerializationManager oldFormSerializer = new FormSerializationManagerImpl();
FormDefinitionSerializer formDefinitionSerializer = migrationContext.getCDIWrapper().getFormDefinitionSerializer();
Function<Resource<Form>, String> originaldFormSerializationFunction = formResource -> {
Form originalForm = formResource.get();
originalForm.setMigrationStep(getStep());
return oldFormSerializer.generateFormXML(originalForm, migrationContext.getSystem());
};
Function<Resource<FormDefinition>, String> newFormSerializationFuncion = formResource -> formDefinitionSerializer.serialize(formResource.get());
migrationContext.getSummaries().forEach(summary -> {
if (summary.getResult().isSuccess()) {
serializeResource(summary.getOriginalForm().getPath(), originaldFormSerializationFunction.apply(summary.getOriginalForm()), migrationContext);
serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
}
});
migrationContext.getExtraSummaries().forEach(summary -> {
serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
});
}
Aggregations