Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DB========================================================================
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://IPv4/oss", "root", "root");
- ResultSet rs = null;
- PreparedStatement ps = null;
- String query = "SELECT * from table";
- ps = sqlConnection.prepareStatement(query);
- rs = ps.executeQuery();
- if(!rs.isBeforeFirst())
- {
- System.err.println((new StringBuilder("No results returned from the query : ")).append(query).toString());
- System.err.println("Please check the query");
- System.exit(1);
- }
- ResultSetMetaData metaData = rs.getMetaData();
- Map columnvalueMap;
- for(; rs.next(); jsonmap.put(keyName, columnvalueMap)) //md5
- {
- columnvalueMap = new HashMap();
- for(int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++)
- if(metaData.getColumnLabel(columnIndex).equals("md5"))
- keyName = rs.getString("md5").toLowerCase();
- else if(rs.getString(metaData.getColumnName(columnIndex)) != null)
- columnvalueMap.put(metaData.getColumnLabel(columnIndex), rs.getString(metaData.getColumnName(columnIndex)));
- else
- columnvalueMap.put(metaData.getColumnLabel(columnIndex), "");
- }
- jsonObject = new JSONObject(JSONValue.toJSONString(jsonmap));
- //DB========================================================================
- //Protex=====================================================================
- ProtexServerProxy myProtexServer = new ProtexServerProxy(serverUri, username, password, connectionTimeout)
- ProjectApi projectApi = myProtexServer.getProjectApi();
- IdentificationApi identificationApi = myProtexServer.getIdentificationApi();
- BomApi bomApi = myProtexServer.getBomApi();
- LocalComponentApi localComponentApi = myProtexServer.getLocalComponentApi();
- CodeTreeApi codeTreeApi = myProtexServer.getCodeTreeApi(0L);
- LicenseApi licenseApi = myProtexServer.getLicenseApi();
- //get project name
- String projectId = projectApi.getProjectByName(projectName).getProjectId()
- //get BOM components
- List bomComponents = bomApi.getBomComponents(projectId);
- //getlocalcomponents
- LocalComponentPageFilter componentPageFilter = PageFilterFactory.getAllRows(LocalComponentColumn.COMPONENT_NAME);
- List localComponents = localComponentApi.getLocalComponents(projectId, componentPageFilter);
- //code tree
- String ROOT = "/";
- Prepare codeTreeNodeRequest
- CodeTreeNodeRequest codeTreeNodeRequest = new CodeTreeNodeRequest();
- codeTreeNodeRequest.getIncludedNodeTypes().addAll(CodeTreeUtilities.ALL_CODE_TREE_NODE_TYPES);
- codeTreeNodeRequest.setDepth(CodeTreeUtilities.INFINITE_DEPTH);
- codeTreeNodeRequest.setIncludeParentNode(Boolean.valueOf(true));
- codeTreeNodeRequest.getCounts().add(NodeCountType.PENDING_ID_ALL);
- List nodes = codeTreeApi.getCodeTreeNodes(projectId, ROOT, codeTreeNodeRequest);
- //licenseApi
- List typeFilter = new ArrayList();
- typeFilter.add(LicenseOriginType.STANDARD);
- typeFilter.add(LicenseOriginType.CUSTOM);
- typeFilter.add(LicenseOriginType.MODIFIED_STANDARD);
- LicenseInfoPageFilter pageFilter = PageFilterFactory.getAllRows(LicenseInfoColumn.LICENSE_NAME);
- List licenses = licenseApi.getLicenses(typeFilter, pageFilter);
- //perform identification
- Prepare identification request
- IdentificationRequest identificationRequest = new IdentificationRequest();
- identificationRequest.setIdentifiedComponentKey(componentKey);
- identificationRequest.setIdentifiedUsageLevel(UsageLevel.COMPONENT_DYNAMIC_LIBRARY);
- actual DeclaredIdentification
- identificationApi.addDeclaredIdentification(projectId, nodeName, identificationRequest, BomRefreshMode.SKIP);
- //Protex=====================================================================
- //main========================
- rootFolderFileList = CodeTree.fetchCodeTreeNodes(projectId, codeTreeApi);
- Iterator iterator = rootFolderFileList.iterator();
- while(iterator.hasNext())
- {
- CodeTreeNode subFolderFileList = (CodeTreeNode)iterator.next();
- Map countMap = CodeTreeUtilities.getNodeCountMap(subFolderFileList);
- filePendingCount = ((Long)countMap.get(NodeCountType.PENDING_ID_ALL)).longValue();
- nodeName = subFolderFileList.getName();
- if(filePendingCount <= 0L || !subFolderFileList.getNodeType().toString().equalsIgnoreCase("FILE"))
- continue;
- fileIndex++;
- System.out.println((new StringBuilder(String.valueOf(fileIndex))).append(") ").append(subFolderFileList.getName()).toString());
- dllFileName = nodeName.replaceFirst(".*/(\\w+)", "$1");
- sourceFileInfoNodes = codeTreeApi.getFileInfo(projectId, nodeName, CodeTreeUtilities.SINGLE_NODE, Boolean.valueOf(true), null);
- for(Iterator iterator2 = sourceFileInfoNodes.iterator(); iterator2.hasNext();)
- {
- SourceFileInfoNode sourceFileInfoNode = (SourceFileInfoNode)iterator2.next();
- System.out.println((new StringBuilder("MD5:")).append(sourceFileInfoNode.getExactChecksum()).toString());
- dllFileMD5Sum = sourceFileInfoNode.getExactChecksum();
- }
- try
- {
- System.out.println((new StringBuilder("\t Searching for rules from DB for File '")).append(dllFileName).append("'").toString());
- componentDetailsfromRules = dllRulesJSON.getJSONObject(dllFileMD5Sum);
- componentNamefromRules = componentDetailsfromRules.getString("component_name");
- componentVersionfromRules = componentDetailsfromRules.getString("component_version");
- componentHomepagefromRules = componentDetailsfromRules.getString("homepage");
- componentLicenseNamefromRules = componentDetailsfromRules.getString("component_license");
- componentCommentfromRules = componentDetailsfromRules.getString("component_comment");
- System.out.println((new StringBuilder("\t Rules found for File ")).append(dllFileName).toString());
- }
- catch(JSONException e)
- {
- if(e.getMessage().contains("not found"))
- {
- System.err.println((new StringBuilder("\t No rules found for the File : '")).append(nodeName).append("' . Hence Skipping identification").toString());
- continue;
- }
- e.printStackTrace();
- }
- // Boolean bomExists;
- try
- {
- System.out.println((new StringBuilder("\t Searching for already existing BOM for component '")).append(componentNamefromRules).append("' with version '").append(componentVersionfromRules).append("' and homepage '").append(componentHomepagefromRules).append("'").toString());
- componentDetailsfromBom = (Map)bomLocalComponentsMap.get(componentNamefromRules);
- componentVersionfromBom = (String)componentDetailsfromBom.get("component_version");
- componentHomepagefromBom = (String)componentDetailsfromBom.get("component_homepage");
- componentLicenseNamefromBom = (String)componentDetailsfromBom.get("component_license");
- bomComponentKey = (ComponentKey)componentDetailsfromBom.get("component_key");
- if(componentVersionfromRules.equals(componentVersionfromBom) && componentHomepagefromRules.equals(componentHomepagefromBom) && componentLicenseNamefromRules.equals(componentLicenseNamefromBom))
- {
- bomExists = Boolean.valueOf(true);
- System.out.println((new StringBuilder("\t Already BOM exists for the component '")).append(componentNamefromRules).append("'. Hence same BOM Component will be reused").toString());
- } else
- {
- System.out.println((new StringBuilder("\t No components found for File : '")).append(nodeName).append("'. Hence new local component would be created").toString());
- bomExists = Boolean.valueOf(false);
- }
- }
- catch(Exception e)
- {
- System.out.println((new StringBuilder("\t Exception:No components found for File : '")).append(nodeName).append("'. Hence new local component would be created").toString());
- bomExists = Boolean.valueOf(false);
- }
- //ComponentKey localComponentKey;
- if(bomExists.booleanValue())
- {
- localComponentKey = bomComponentKey;
- } else
- {
- System.out.println((new StringBuilder("\t Creating new local component for component name : '")).append(componentNamefromRules).append("'").toString());
- LocalComponentRequest localComponentRequest = new LocalComponentRequest();
- localComponentRequest.setName(componentNamefromRules);
- localComponentRequest.setHomePage(componentHomepagefromRules);
- localComponentRequest.setVersionLabel(componentVersionfromRules);
- String licenseId = licenseJSON.getJSONObject(componentLicenseNamefromRules.toLowerCase()).getString("license_id");
- LocalLicenseRequest localLicenseRequest = new LocalLicenseRequest();
- localLicenseRequest.setBasedOnLicenseId(licenseId);
- try
- {
- localComponentKey = localComponentApi.createLocalComponent(projectId, localComponentRequest, localLicenseRequest);
- }
- catch(SdkFault e)
- {
- System.err.println((new StringBuilder("createLocalComponent() failed: ")).append(e.getMessage()).toString());
- throw new RuntimeException(e);
- }
- Map columnMap = new HashMap();
- columnMap.put("component_id", localComponentKey.getComponentId());
- columnMap.put("component_key", localComponentKey);
- columnMap.put("component_homepage", componentHomepagefromRules);
- columnMap.put("component_version", componentVersionfromRules);
- columnMap.put("license_id", licenseId);
- columnMap.put("component_license", componentLicenseNamefromRules);
- bomLocalComponentsMap.put(componentNamefromRules, columnMap);
- }
- Identification.applyIdentification(projectId, identificationApi, nodeName, localComponentKey);
- ComponentCommentMap.put(localComponentKey, componentCommentfromRules);
- }
- System.out.println("Identification is completed");
- //main=========================
- //comp comment add
- bomApi.setComponentComment(projectId, component key, component comment)
- //bom refresh
- bomApi.refreshBom(projectId,booleanValue refreshAllFiles,booleanValue asynchronousRefresh);
Add Comment
Please, Sign In to add comment