@Override public boolean preProcess( RefactorType refactorType, IResource refactoredResource, IProgressMonitor monitor) { if (RefactorResourcesUtils.isClosedProject(refactoredResource)) { /* * By definition, a closed project will not contain any open VDB editors */ return true; } // Find and show affected VDBs final Collection<IFile> allVdbResourcesInProject = WorkspaceResourceFinderUtil.getProjectFileResources( refactoredResource.getProject(), WorkspaceResourceFinderUtil.VDB_RESOURCE_FILTER); Collection<IFile> targetVdbs = new ArrayList<IFile>(); Collection<VdbEditor> openVdbEditors = new ArrayList<VdbEditor>(); for (IFile theVdb : allVdbResourcesInProject) { if (refactoredResource instanceof IFolder) { IFolder folder = (IFolder) refactoredResource; try { IResource[] members = folder.members(); for (int i = 0; i < members.length; ++i) { preProcess(refactorType, members[i], monitor); } } catch (CoreException ex) { // Consider what TODO } } else if (refactoredResource instanceof IFile) { if (VdbUtil.modelInVdb(theVdb, (IFile) refactoredResource)) { targetVdbs.add(theVdb); VdbEditor vdbEditor = getVdbEditorForFile(theVdb); if (vdbEditor != null) { openVdbEditors.add(vdbEditor); } } } } if (targetVdbs.isEmpty()) return true; for (VdbEditor editor : openVdbEditors) { closeVdbEditor(editor); } return true; }
@Test public void testCommentReader() throws Exception { MockFileBuilder portfolioXmlFile = VdbTestUtils.mockPortfolioVdbXmlFile(); File portfolioFile = portfolioXmlFile.getRealFile(); InputStream fileStream = new FileInputStream(portfolioFile); JAXBContext jaxbContext = JAXBContext.newInstance(new Class<?>[] {VdbElement.class}); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(VdbUtil.getManifestSchema()); VdbElement manifest = (VdbElement) unmarshaller.unmarshal(fileStream); fileStream.close(); CommentReader reader = new CommentReader(manifest); reader.read(portfolioFile); CommentSets vdbComments = manifest.getComments(); assertNotNull(vdbComments); assertEquals(2, vdbComments.size()); checkComment(Comments.VDB_TITLE, vdbComments, EMPTY_STRING, 0); checkComment(Comments.VDB_TITLE_2, vdbComments, EMPTY_STRING, 1); checkComment(Comments.VDB_DESCRIPTION, vdbComments, DESCRIPTION, 0); assertEquals(1, manifest.getProperties().size()); PropertyElement propertyElement = manifest.getProperties().get(0); checkComment(Comments.USE_CONNECTOR_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0); ModelElement modelElement = manifest.getModels().get(0); assertEquals("MarketData", modelElement.getName()); checkComment(Comments.MODEL_MARKETDATA, modelElement.getComments(), EMPTY_STRING, 0); SourceElement sourceElement = modelElement.getSources().get(0); assertEquals("text-connector", sourceElement.getName()); checkComment(Comments.MARKETDATA_TEXT_CONNECTOR, sourceElement.getComments(), EMPTY_STRING, 0); modelElement = manifest.getModels().get(1); assertEquals("Accounts", modelElement.getName()); propertyElement = modelElement.getProperties().get(0); assertNotNull(propertyElement); checkComment( Comments.ACCOUNTS_USEFULLSCHEMA_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0); sourceElement = modelElement.getSources().get(0); assertEquals("h2-connector", sourceElement.getName()); checkComment(Comments.ACCOUNT_H2_CONNECTOR, sourceElement.getComments(), EMPTY_STRING, 0); modelElement = manifest.getModels().get(2); assertEquals("PersonalValuations", modelElement.getName()); propertyElement = modelElement.getProperties().get(0); assertNotNull(propertyElement); checkComment( Comments.IMPORTER_HEADER_ROW_NUMBER_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0); propertyElement = modelElement.getProperties().get(1); assertNotNull(propertyElement); checkComment( Comments.IMPORT_EXCEL_FILE_NAME_PROPERTY, propertyElement.getComments(), EMPTY_STRING, 0); MetadataElement metadataElement = modelElement.getMetadata().get(0); assertNotNull(metadataElement); checkComment(Comments.METADATA_ELEMENT, metadataElement.getComments(), EMPTY_STRING, 0); DataRoleElement dataRoleElement = manifest.getDataPolicies().get(0); assertNotNull(dataRoleElement); checkComment(Comments.DATA_ROLE, dataRoleElement.getComments(), EMPTY_STRING, 0); checkComment(Comments.DATA_ROLE_DESCRIPTION, dataRoleElement.getComments(), DESCRIPTION, 0); checkComment( Comments.SUPERVISOR_MAPPED_ROLE, dataRoleElement.getComments(), MAPPED_ROLE_NAME + HYPHEN + "supervisor", 0); checkComment( Comments.DEPT_SUPER_MAPPED_ROLE, dataRoleElement.getComments(), MAPPED_ROLE_NAME + HYPHEN + "dept-supervisor", 0); List<PermissionElement> permissionElements = dataRoleElement.getPermissions(); assertNotNull(permissionElements); assertTrue(!permissionElements.isEmpty()); PermissionElement permissionElement = permissionElements.get(0); assertEquals("Accounts", permissionElement.getResourceName()); checkComment( Comments.PERMISSION_ON_ACCOUNTS_TABLE, permissionElement.getComments(), EMPTY_STRING, 0); checkComment( Comments.RESOURCE_NAME_REFERENCED_BY_PERMISSION, permissionElement.getComments(), RESOURCE_NAME, 0); checkComment(Comments.DENY_CREATE, permissionElement.getComments(), ALLOW_CREATE, 0); checkComment(Comments.ALLOW_READ, permissionElement.getComments(), ALLOW_READ, 0); checkComment(Comments.ALLOW_UPDATE, permissionElement.getComments(), ALLOW_UPDATE, 0); permissionElement = permissionElements.get(1); assertEquals("Accounts.Customer", permissionElement.getResourceName()); ConditionElement conditionElement = permissionElement.getCondition(); checkComment( Comments.PERMISSION_USING_A_CONDITION, conditionElement.getComments(), EMPTY_STRING, 0); permissionElement = permissionElements.get(2); assertEquals("Accounts.Customer.SSN", permissionElement.getResourceName()); MaskElement maskElement = permissionElement.getMask(); checkComment(Comments.PERMISSION_MASK, maskElement.getComments(), EMPTY_STRING, 0); }