Guest User

Untitled

a guest
Dec 2nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. //DB========================================================================
  2. Class.forName("com.mysql.jdbc.Driver");
  3. con = DriverManager.getConnection("jdbc:mysql://IPv4/oss", "root", "root");
  4.  
  5. ResultSet rs = null;
  6. PreparedStatement ps = null;
  7. String query = "SELECT * from table";
  8. ps = sqlConnection.prepareStatement(query);
  9. rs = ps.executeQuery();
  10. if(!rs.isBeforeFirst())
  11. {
  12. System.err.println((new StringBuilder("No results returned from the query : ")).append(query).toString());
  13. System.err.println("Please check the query");
  14. System.exit(1);
  15. }
  16. ResultSetMetaData metaData = rs.getMetaData();
  17. Map columnvalueMap;
  18. for(; rs.next(); jsonmap.put(keyName, columnvalueMap)) //md5
  19. {
  20. columnvalueMap = new HashMap();
  21. for(int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++)
  22. if(metaData.getColumnLabel(columnIndex).equals("md5"))
  23. keyName = rs.getString("md5").toLowerCase();
  24. else if(rs.getString(metaData.getColumnName(columnIndex)) != null)
  25. columnvalueMap.put(metaData.getColumnLabel(columnIndex), rs.getString(metaData.getColumnName(columnIndex)));
  26. else
  27. columnvalueMap.put(metaData.getColumnLabel(columnIndex), "");
  28.  
  29. }
  30.  
  31. jsonObject = new JSONObject(JSONValue.toJSONString(jsonmap));
  32. //DB========================================================================
  33.  
  34. //Protex=====================================================================
  35. ProtexServerProxy myProtexServer = new ProtexServerProxy(serverUri, username, password, connectionTimeout)
  36.  
  37. ProjectApi projectApi = myProtexServer.getProjectApi();
  38. IdentificationApi identificationApi = myProtexServer.getIdentificationApi();
  39. BomApi bomApi = myProtexServer.getBomApi();
  40. LocalComponentApi localComponentApi = myProtexServer.getLocalComponentApi();
  41. CodeTreeApi codeTreeApi = myProtexServer.getCodeTreeApi(0L);
  42. LicenseApi licenseApi = myProtexServer.getLicenseApi();
  43.  
  44. //get project name
  45. String projectId = projectApi.getProjectByName(projectName).getProjectId()
  46.  
  47. //get BOM components
  48. List bomComponents = bomApi.getBomComponents(projectId);
  49.  
  50.  
  51. //getlocalcomponents
  52.  
  53. LocalComponentPageFilter componentPageFilter = PageFilterFactory.getAllRows(LocalComponentColumn.COMPONENT_NAME);
  54.  
  55. List localComponents = localComponentApi.getLocalComponents(projectId, componentPageFilter);
  56.  
  57. //code tree
  58. String ROOT = "/";
  59.  
  60. Prepare codeTreeNodeRequest
  61. CodeTreeNodeRequest codeTreeNodeRequest = new CodeTreeNodeRequest();
  62. codeTreeNodeRequest.getIncludedNodeTypes().addAll(CodeTreeUtilities.ALL_CODE_TREE_NODE_TYPES);
  63. codeTreeNodeRequest.setDepth(CodeTreeUtilities.INFINITE_DEPTH);
  64. codeTreeNodeRequest.setIncludeParentNode(Boolean.valueOf(true));
  65. codeTreeNodeRequest.getCounts().add(NodeCountType.PENDING_ID_ALL);
  66.  
  67. List nodes = codeTreeApi.getCodeTreeNodes(projectId, ROOT, codeTreeNodeRequest);
  68.  
  69. //licenseApi
  70.  
  71. List typeFilter = new ArrayList();
  72. typeFilter.add(LicenseOriginType.STANDARD);
  73. typeFilter.add(LicenseOriginType.CUSTOM);
  74. typeFilter.add(LicenseOriginType.MODIFIED_STANDARD);
  75.  
  76. LicenseInfoPageFilter pageFilter = PageFilterFactory.getAllRows(LicenseInfoColumn.LICENSE_NAME);
  77.  
  78.  
  79. List licenses = licenseApi.getLicenses(typeFilter, pageFilter);
  80.  
  81. //perform identification
  82.  
  83. Prepare identification request
  84. IdentificationRequest identificationRequest = new IdentificationRequest();
  85. identificationRequest.setIdentifiedComponentKey(componentKey);
  86. identificationRequest.setIdentifiedUsageLevel(UsageLevel.COMPONENT_DYNAMIC_LIBRARY);
  87.  
  88. actual DeclaredIdentification
  89. identificationApi.addDeclaredIdentification(projectId, nodeName, identificationRequest, BomRefreshMode.SKIP);
  90.  
  91. //Protex=====================================================================
  92.  
  93. //main========================
  94. rootFolderFileList = CodeTree.fetchCodeTreeNodes(projectId, codeTreeApi);
  95. Iterator iterator = rootFolderFileList.iterator();
  96. while(iterator.hasNext())
  97. {
  98. CodeTreeNode subFolderFileList = (CodeTreeNode)iterator.next();
  99. Map countMap = CodeTreeUtilities.getNodeCountMap(subFolderFileList);
  100. filePendingCount = ((Long)countMap.get(NodeCountType.PENDING_ID_ALL)).longValue();
  101. nodeName = subFolderFileList.getName();
  102. if(filePendingCount <= 0L || !subFolderFileList.getNodeType().toString().equalsIgnoreCase("FILE"))
  103. continue;
  104. fileIndex++;
  105. System.out.println((new StringBuilder(String.valueOf(fileIndex))).append(") ").append(subFolderFileList.getName()).toString());
  106. dllFileName = nodeName.replaceFirst(".*/(\\w+)", "$1");
  107. sourceFileInfoNodes = codeTreeApi.getFileInfo(projectId, nodeName, CodeTreeUtilities.SINGLE_NODE, Boolean.valueOf(true), null);
  108. for(Iterator iterator2 = sourceFileInfoNodes.iterator(); iterator2.hasNext();)
  109. {
  110. SourceFileInfoNode sourceFileInfoNode = (SourceFileInfoNode)iterator2.next();
  111. System.out.println((new StringBuilder("MD5:")).append(sourceFileInfoNode.getExactChecksum()).toString());
  112. dllFileMD5Sum = sourceFileInfoNode.getExactChecksum();
  113. }
  114.  
  115. try
  116. {
  117. System.out.println((new StringBuilder("\t Searching for rules from DB for File '")).append(dllFileName).append("'").toString());
  118. componentDetailsfromRules = dllRulesJSON.getJSONObject(dllFileMD5Sum);
  119. componentNamefromRules = componentDetailsfromRules.getString("component_name");
  120. componentVersionfromRules = componentDetailsfromRules.getString("component_version");
  121. componentHomepagefromRules = componentDetailsfromRules.getString("homepage");
  122. componentLicenseNamefromRules = componentDetailsfromRules.getString("component_license");
  123. componentCommentfromRules = componentDetailsfromRules.getString("component_comment");
  124. System.out.println((new StringBuilder("\t Rules found for File ")).append(dllFileName).toString());
  125. }
  126. catch(JSONException e)
  127. {
  128. if(e.getMessage().contains("not found"))
  129. {
  130. System.err.println((new StringBuilder("\t No rules found for the File : '")).append(nodeName).append("' . Hence Skipping identification").toString());
  131. continue;
  132. }
  133. e.printStackTrace();
  134. }
  135. // Boolean bomExists;
  136. try
  137. {
  138. 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());
  139. componentDetailsfromBom = (Map)bomLocalComponentsMap.get(componentNamefromRules);
  140. componentVersionfromBom = (String)componentDetailsfromBom.get("component_version");
  141. componentHomepagefromBom = (String)componentDetailsfromBom.get("component_homepage");
  142. componentLicenseNamefromBom = (String)componentDetailsfromBom.get("component_license");
  143. bomComponentKey = (ComponentKey)componentDetailsfromBom.get("component_key");
  144. if(componentVersionfromRules.equals(componentVersionfromBom) && componentHomepagefromRules.equals(componentHomepagefromBom) && componentLicenseNamefromRules.equals(componentLicenseNamefromBom))
  145. {
  146. bomExists = Boolean.valueOf(true);
  147. System.out.println((new StringBuilder("\t Already BOM exists for the component '")).append(componentNamefromRules).append("'. Hence same BOM Component will be reused").toString());
  148. } else
  149. {
  150. System.out.println((new StringBuilder("\t No components found for File : '")).append(nodeName).append("'. Hence new local component would be created").toString());
  151. bomExists = Boolean.valueOf(false);
  152. }
  153. }
  154. catch(Exception e)
  155. {
  156. System.out.println((new StringBuilder("\t Exception:No components found for File : '")).append(nodeName).append("'. Hence new local component would be created").toString());
  157. bomExists = Boolean.valueOf(false);
  158. }
  159. //ComponentKey localComponentKey;
  160. if(bomExists.booleanValue())
  161. {
  162. localComponentKey = bomComponentKey;
  163. } else
  164. {
  165. System.out.println((new StringBuilder("\t Creating new local component for component name : '")).append(componentNamefromRules).append("'").toString());
  166. LocalComponentRequest localComponentRequest = new LocalComponentRequest();
  167. localComponentRequest.setName(componentNamefromRules);
  168. localComponentRequest.setHomePage(componentHomepagefromRules);
  169. localComponentRequest.setVersionLabel(componentVersionfromRules);
  170. String licenseId = licenseJSON.getJSONObject(componentLicenseNamefromRules.toLowerCase()).getString("license_id");
  171. LocalLicenseRequest localLicenseRequest = new LocalLicenseRequest();
  172. localLicenseRequest.setBasedOnLicenseId(licenseId);
  173. try
  174. {
  175. localComponentKey = localComponentApi.createLocalComponent(projectId, localComponentRequest, localLicenseRequest);
  176. }
  177. catch(SdkFault e)
  178. {
  179. System.err.println((new StringBuilder("createLocalComponent() failed: ")).append(e.getMessage()).toString());
  180. throw new RuntimeException(e);
  181. }
  182. Map columnMap = new HashMap();
  183. columnMap.put("component_id", localComponentKey.getComponentId());
  184. columnMap.put("component_key", localComponentKey);
  185. columnMap.put("component_homepage", componentHomepagefromRules);
  186. columnMap.put("component_version", componentVersionfromRules);
  187. columnMap.put("license_id", licenseId);
  188. columnMap.put("component_license", componentLicenseNamefromRules);
  189. bomLocalComponentsMap.put(componentNamefromRules, columnMap);
  190. }
  191. Identification.applyIdentification(projectId, identificationApi, nodeName, localComponentKey);
  192. ComponentCommentMap.put(localComponentKey, componentCommentfromRules);
  193. }
  194. System.out.println("Identification is completed");
  195.  
  196. //main=========================
  197.  
  198. //comp comment add
  199. bomApi.setComponentComment(projectId, component key, component comment)
  200.  
  201. //bom refresh
  202. bomApi.refreshBom(projectId,booleanValue refreshAllFiles,booleanValue asynchronousRefresh);
Add Comment
Please, Sign In to add comment