@Override
public Form getFormById( String ctxUID, long formId ) {
FormEditorContext editorContext = formEditorContextManager.getRootEditorContext( ctxUID );
if ( editorContext != null ) {
try {
if ( editorContext.getForm().getId().equals( new Long( formId ) ) ) {
return editorContext.getForm();
}
Path currentForm = Paths.convert( ioService.get( new URI( editorContext.getPath() ) ) );
Project project = projectService.resolveProject( currentForm );
FileUtils utils = FileUtils.getInstance();
List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<org.uberfire.java.nio.file.Path>();
nioPaths.add( Paths.convert( project.getRootPath() ) );
Collection<FileUtils.ScanResult> forms = utils.scan( ioService, nioPaths, "form", true );
String header = formSerializationManager.generateHeaderFormFormId( formId );
for ( FileUtils.ScanResult form : forms ) {
org.uberfire.java.nio.file.Path formPath = form.getFile();
org.uberfire.java.nio.file.Path path = Paths.convert( project.getRootPath() ).resolve( MAIN_RESOURCES_PATH ).resolve( formPath );
String xml = ioService.readAllString( path ).trim();
if ( xml.startsWith( header ) ) {
return formSerializationManager.loadFormFromXML( xml );
}
}
} catch ( Exception e ) {
log.warn( "Error getting form {} from context {}: {}", formId, ctxUID, e );
}
}
return null;
}