Skip to content

Commit

Permalink
Fix Package name follow order
Browse files Browse the repository at this point in the history
  • Loading branch information
fvl-phuong authored Jun 9, 2020
1 parent 019b75c commit efa8393
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/main/java/com/spdx/service/ExportExcelFileImpl.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*------------------------------------------------------------------------*/
// All Rights Reserved, Copyright(C) FUJITSU LIMITED 2019
// All Rights Reserved, Copyright(C) FUJITSU LIMITED 2020
/*------------------------------------------------------------------------*/

package com.spdx.service;

import java.io.File;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -13,11 +14,13 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

Expand All @@ -34,6 +37,7 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -97,12 +101,7 @@ public String export(String spdxFields) throws Exception {
Set<String> packageCommentExtendsHeader = new LinkedHashSet<String>();
for (SpdxRelease spdxRelease : lstRelease) {
List<PackageCommentExtend> packageCommentExtends = spdxRelease.getPackageCommentExtends();
// Map<String, String> packageCommentExtends = spdxRelease.getPackageCommentExtends();
if (packageCommentExtends != null) {
// for (Map.Entry<String,String> entry : packageCommentExtends.entrySet()) {
// packageCommentExtendsHeader.add(entry.getKey());
// }

for (PackageCommentExtend packageCommentExtend : packageCommentExtends) {
packageCommentExtendsHeader.add(packageCommentExtend.getKey());
}
Expand Down Expand Up @@ -265,7 +264,6 @@ public String export(String spdxFields) throws Exception {
for (int i = 0; i < lstSpdxFields.size(); i++) {
sheet.autoSizeColumn(i);
}

DateFormat format = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String date = format.format(new Date()).replace("-", "").replace(" ", "").replace(":", "");

Expand Down Expand Up @@ -296,10 +294,35 @@ private List<String> getListApiComponent(ResponseToken token) throws Exception {
if ((result.getResponseCode() == 200 || result.getResponseCode() == 201) && result.getBody().contains("sw360:components")) {
lstComponent = (new JSONObject(result.getBody())).getJSONObject("_embedded")
.getJSONArray("sw360:components");
for (Object object : lstComponent) {

//Sort component array
JSONArray sortedJsonArray = new JSONArray();
List<JSONObject> list = new ArrayList<JSONObject>();
for(int i = 0; i < lstComponent.length(); i++) {
list.add(lstComponent.getJSONObject(i));
}
Collections.sort(list, new Comparator<JSONObject>() {
private static final String KEY_NAME = "name";
@Override
public int compare(JSONObject a, JSONObject b) {
String str1 = new String();
String str2 = new String();
try {
str1 = (String)a.get(KEY_NAME);
str2 = (String)b.get(KEY_NAME);
} catch(JSONException e) {
e.printStackTrace();
}
return str1.toUpperCase().compareTo(str2.toUpperCase());
}
});
for(int i = 0; i < lstComponent.length(); i++) {
sortedJsonArray.put(list.get(i));
}
for (Object object : sortedJsonArray) {
if (object instanceof JSONObject)
lstApiComponent
.add(((JSONObject) object).getJSONObject("_links").getJSONObject("self").getString("href"));
.add(((JSONObject) object).getJSONObject("_links").getJSONObject("self").getString("href"));
}
}
return lstApiComponent;
Expand Down Expand Up @@ -330,9 +353,7 @@ private List<SpdxRelease> getListRelease(ResponseToken token) throws Exception {
lstRelease.add(callout.getRelease(apiRelease, token));
}
}

return lstRelease;

}

private List<SpdxLicense> getLicenses(ResponseToken token) throws Exception {
Expand All @@ -350,7 +371,7 @@ private List<SpdxLicense> getLicenses(ResponseToken token) throws Exception {
for (Object object : lstComponent) {
if (object instanceof JSONObject)
lstApiLicenses
.add(((JSONObject) object).getJSONObject("_links").getJSONObject("self").getString("href"));
.add(((JSONObject) object).getJSONObject("_links").getJSONObject("self").getString("href"));
}
}

Expand All @@ -359,5 +380,4 @@ private List<SpdxLicense> getLicenses(ResponseToken token) throws Exception {
lstLicenses.add(callout.getLicense(url, token));
return lstLicenses;
}

}

0 comments on commit efa8393

Please sign in to comment.