From ced018359d3927a106af895784d8dc2a274deb83 Mon Sep 17 00:00:00 2001 From: domjos1994 Date: Tue, 29 Oct 2019 18:15:12 +0100 Subject: [PATCH] solve bug 0000285 --- .../activities/ExportActivity.java | 3 - .../activities/VersionActivity.java | 64 +++++++++++++++---- app/src/main/res/menu/menu_versions.xml | 27 ++++++++ app/src/main/res/values-de/strings.xml | 3 + app/src/main/res/values/strings.xml | 3 + .../unitrackerlibrary/export/ObjectPDF.java | 37 ++++++++++- .../unitrackerlibrary/export/TrackerPDF.java | 6 ++ .../services/tracker/MantisBT.java | 20 ++++-- .../unitrackerlibrary/tasks/ExportTask.java | 59 +++++++++++------ 9 files changed, 183 insertions(+), 39 deletions(-) create mode 100644 app/src/main/res/menu/menu_versions.xml diff --git a/app/src/main/java/de/domjos/unitrackermobile/activities/ExportActivity.java b/app/src/main/java/de/domjos/unitrackermobile/activities/ExportActivity.java index 552e111a..3143260a 100644 --- a/app/src/main/java/de/domjos/unitrackermobile/activities/ExportActivity.java +++ b/app/src/main/java/de/domjos/unitrackermobile/activities/ExportActivity.java @@ -25,7 +25,6 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; -import android.widget.CompoundButton; import android.widget.ImageButton; import android.widget.Spinner; import android.widget.TableLayout; @@ -37,12 +36,10 @@ import com.github.angads25.filepicker.model.DialogConfigs; import com.github.angads25.filepicker.model.DialogProperties; import com.github.angads25.filepicker.view.FilePickerDialog; -import com.github.mikephil.charting.utils.FileUtils; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; -import java.nio.file.Files; import java.util.Date; import java.util.LinkedList; import java.util.List; diff --git a/app/src/main/java/de/domjos/unitrackermobile/activities/VersionActivity.java b/app/src/main/java/de/domjos/unitrackermobile/activities/VersionActivity.java index 52398cce..bab078cf 100644 --- a/app/src/main/java/de/domjos/unitrackermobile/activities/VersionActivity.java +++ b/app/src/main/java/de/domjos/unitrackermobile/activities/VersionActivity.java @@ -18,6 +18,9 @@ package de.domjos.unitrackermobile.activities; +import android.os.Environment; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.CheckBox; @@ -26,8 +29,11 @@ import android.widget.Spinner; import android.widget.TableRow; +import androidx.annotation.NonNull; + import com.google.android.material.bottomnavigation.BottomNavigationView; +import java.io.File; import java.util.Date; import de.domjos.unitrackerlibrary.interfaces.IBugService; @@ -35,7 +41,9 @@ import de.domjos.unitrackerlibrary.model.ListObject; import de.domjos.unitrackerlibrary.model.projects.Version; import de.domjos.unitrackerlibrary.services.engine.Authentication; +import de.domjos.unitrackerlibrary.tasks.ExportTask; import de.domjos.unitrackerlibrary.tasks.VersionTask; +import de.domjos.unitrackerlibrary.utils.Converter; import de.domjos.unitrackerlibrary.utils.MessageHelper; import de.domjos.unitrackermobile.R; import de.domjos.unitrackermobile.custom.AbstractActivity; @@ -277,6 +285,7 @@ private void updateUITrackerSpecific() { if (tracker != null) { switch (tracker) { case MantisBT: + case Local: this.rowVersionReleasedAt.setVisibility(View.VISIBLE); this.rowVersionReleased.setVisibility(View.VISIBLE); this.rowVersionDeprecated.setVisibility(View.VISIBLE); @@ -290,6 +299,7 @@ private void updateUITrackerSpecific() { this.chkVersionDeprecated.setOnCheckedChangeListener((buttonView, isChecked) -> this.chkVersionReleased.setVisibility(isChecked ? View.GONE : View.VISIBLE)); break; case YouTrack: + case OpenProject: this.rowVersionReleasedAt.setVisibility(View.VISIBLE); this.rowVersionReleased.setVisibility(View.VISIBLE); this.rowVersionDeprecated.setVisibility(View.VISIBLE); @@ -307,23 +317,55 @@ private void updateUITrackerSpecific() { this.rowVersionDeprecated.setVisibility(View.VISIBLE); this.rowVersionDeprecated.setVisibility(View.VISIBLE); break; - case OpenProject: - this.rowVersionReleasedAt.setVisibility(View.VISIBLE); - this.rowVersionReleased.setVisibility(View.VISIBLE); - this.rowVersionDeprecated.setVisibility(View.VISIBLE); - break; case Backlog: this.rowVersionReleasedAt.setVisibility(View.VISIBLE); this.rowVersionDeprecated.setVisibility(View.VISIBLE); break; - case Local: - this.rowVersionReleasedAt.setVisibility(View.VISIBLE); - this.rowVersionReleased.setVisibility(View.VISIBLE); - this.rowVersionDeprecated.setVisibility(View.VISIBLE); - this.rowVersionFilter.setVisibility(View.VISIBLE); - break; + } + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_versions, menu); + return true; + } + + @Override + @SuppressWarnings("deprecation") + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + try { + if(item.getItemId()==R.id.menChangelog) { + if(this.currentVersion != null) { + String downloadDir = ""; + File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + if(file!=null) { + downloadDir = file.getAbsolutePath(); + } + Object vid = this.currentVersion.getId(); + Object pid = this.currentProject; + + byte[] bg, icon; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { + bg = Converter.convertDrawableToByteArray(VersionActivity.this.getDrawable(R.drawable.background)); + icon = Converter.convertDrawableToByteArray(VersionActivity.this.getDrawable(R.drawable.ic_launcher_web)); + } else { + bg = Converter.convertDrawableToByteArray(VersionActivity.this.getResources().getDrawable(R.drawable.background)); + icon = Converter.convertDrawableToByteArray(VersionActivity.this.getResources().getDrawable(R.drawable.ic_launcher_web)); + } + ExportTask exportTask = new ExportTask( + VersionActivity.this, bugService, null, pid, downloadDir, + false, R.drawable.ic_bug_report_black_24dp, bg, icon, "", vid); + exportTask.execute(0).get(); + MessageHelper.printMessage(this.getString(R.string.versions_menu_changelog_created), VersionActivity.this); + } else { + MessageHelper.printMessage(this.getString(R.string.versions_menu_changelog_no_selected), VersionActivity.this); + } } + } catch (Exception ex) { + MessageHelper.printException(ex, VersionActivity.this); } + return super.onOptionsItemSelected(item); } } diff --git a/app/src/main/res/menu/menu_versions.xml b/app/src/main/res/menu/menu_versions.xml new file mode 100644 index 00000000..964918b7 --- /dev/null +++ b/app/src/main/res/menu/menu_versions.xml @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7daf4f50..6b3e135c 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -79,6 +79,9 @@ @string/versions_unReleased @string/versions_released + Changelog-PDF generieren + Keine Version ausgewählt! + Changelog wurde erfolgreich im Download-Ordner erstellt Benutzer Login-Name diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5cbcbe9c..a73f0550 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,6 +82,9 @@ @string/versions_unReleased @string/versions_released + Create Changelog as PDF + No Version selected! + Changelog was created successfully in Download-Folder! User Login-Name diff --git a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/ObjectPDF.java b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/ObjectPDF.java index c5ed561b..53246d9b 100644 --- a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/ObjectPDF.java +++ b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/ObjectPDF.java @@ -32,6 +32,7 @@ import com.itextpdf.text.pdf.PdfPageEventHelper; import com.itextpdf.text.pdf.PdfWriter; +import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.AbstractMap; @@ -73,6 +74,36 @@ static void saveObjectToPDF(List lst, String path, byte[] array, byte[] icon) th pdfDocument.close(); } + static void createChangeLog(List issues, String path, byte[] array, byte[] icon, Version version) throws Exception { + Map fonts = new LinkedHashMap<>(); + fonts.put(H1, new Font(Font.FontFamily.HELVETICA, 18, Font.BOLDITALIC, BaseColor.BLACK)); + fonts.put(H2, new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK)); + fonts.put(H3, new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.BLACK)); + fonts.put(BODY, new Font(Font.FontFamily.HELVETICA, 14, Font.NORMAL, BaseColor.BLACK)); + + Document pdfDocument = new Document(); + PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(path + File.separatorChar + "changelog_" + version.getId() + ".pdf")); + writer.setBoxSize("art", new Rectangle(55, 25, 550, 788)); + writer.setPageEvent(new PDFPageEvent(1, array, icon)); + pdfDocument.open(); + ObjectPDF.saveChangeLogToPDF(issues, pdfDocument, fonts, version); + pdfDocument.close(); + } + + + private static void saveChangeLogToPDF(List issues, Document pdfDocument, Map fonts, Version version) throws Exception { + pdfDocument.add(ObjectPDF.addTitle("Changelog of " + version.getTitle(), fonts.get(H1), Paragraph.ALIGN_CENTER)); + pdfDocument.add(ObjectPDF.addEmptyLine(3)); + + List>> bugTable = new LinkedList<>(); + for(Issue issue : issues) { + if(issue.getFixedInVersion().trim().equals(version.getTitle().trim())) { + ObjectPDF.addRowToTable(String.valueOf(issue.getId()), issue.getTitle(), false, bugTable); + } + } + pdfDocument.add(ObjectPDF.addTable(null, null, bugTable)); + } + private static void saveElementToPDF(Object object, Document pdfDocument, Map fonts) throws Exception { if(object instanceof Project) { Project project = (Project) object; @@ -244,7 +275,11 @@ private static PdfPTable addTable(List headers, float[] headerWidth, Lis table.addCell(cell); } } else { - table = new PdfPTable(cells.get(0).size()); + if(cells.size()!=0) { + table = new PdfPTable(cells.get(0).size()); + } else { + table = new PdfPTable(1); + } } for(List> row : cells) { diff --git a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/TrackerPDF.java b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/TrackerPDF.java index d6309c13..1b546d7b 100644 --- a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/TrackerPDF.java +++ b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/export/TrackerPDF.java @@ -27,6 +27,7 @@ import de.domjos.unitrackerlibrary.model.issues.CustomField; import de.domjos.unitrackerlibrary.model.issues.Issue; import de.domjos.unitrackerlibrary.model.projects.Project; +import de.domjos.unitrackerlibrary.model.projects.Version; public final class TrackerPDF extends AbstractTracker { private byte[] array, icon; @@ -43,6 +44,11 @@ public TrackerPDF(IBugService bugService, Type type, T pid, List ids, Stri this.icon = icon; } + public void createChangeLog(Version version) throws Exception { + List issues = (List) ids; + ObjectPDF.createChangeLog(issues, path, array, icon, version); + } + @Override public void doExport() throws Exception { switch (this.type) { diff --git a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/services/tracker/MantisBT.java b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/services/tracker/MantisBT.java index e8cc4585..548d1a64 100644 --- a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/services/tracker/MantisBT.java +++ b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/services/tracker/MantisBT.java @@ -222,11 +222,15 @@ public void deleteVersion(Long id, Long project_id) throws Exception { @Override public long getMaximumNumberOfIssues(Long project_id, IssueFilter filter) throws Exception { - SoapObject request = new SoapObject(super.soapPath, "mc_project_get_issue_headers"); - request.addProperty("project_id", Integer.parseInt(String.valueOf(project_id))); + SoapObject request = new SoapObject(super.soapPath, "mc_filter_search_issue_headers"); request.addProperty("page_number", 1); request.addProperty("per_page", -1); - Object object = this.executeAction(request, "mc_project_get_issue_headers", true); + SoapObject filterObject = new SoapObject(NAMESPACE, "FilterSearchData"); + Vector projects = new Vector<>(); + projects.add(Integer.parseInt(String.valueOf(project_id))); + filterObject.addProperty("project_id", projects); + request.addProperty("filter", filterObject); + Object object = this.executeAction(request, "mc_filter_search_issue_headers", true); object = this.getResult(object); if (object instanceof Vector) { Vector vector = (Vector) object; @@ -255,14 +259,18 @@ public List> getIssues(Long pid, int page, int numberOfItems) throws public List> getIssues(Long pid, int page, int numberOfItems, IssueFilter filter) throws Exception { List> issues = new LinkedList<>(); - SoapObject request = new SoapObject(super.soapPath, "mc_project_get_issue_headers"); - request.addProperty("project_id", Integer.parseInt(String.valueOf(pid))); + SoapObject request = new SoapObject(super.soapPath, "mc_filter_search_issue_headers"); request.addProperty("page_number", page); request.addProperty("per_page", numberOfItems); + SoapObject filterObject = new SoapObject(NAMESPACE, "FilterSearchData"); + Vector projects = new Vector<>(); + projects.add(Integer.parseInt(String.valueOf(pid))); + filterObject.addProperty("project_id", projects); + request.addProperty("filter", filterObject); List enumView = this.getEnums("view_states"); List enumStatus = this.getEnums("status"); - Object object = this.executeAction(request, "mc_project_get_issue_headers", true); + Object object = this.executeAction(request, "mc_filter_search_issue_headers", true); object = this.getResult(object); if (object instanceof Vector) { Vector vector = (Vector) object; diff --git a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/tasks/ExportTask.java b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/tasks/ExportTask.java index 1a20d22a..b2812759 100644 --- a/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/tasks/ExportTask.java +++ b/unitrackerlibrary/src/main/java/de/domjos/unitrackerlibrary/tasks/ExportTask.java @@ -28,14 +28,20 @@ import de.domjos.unitrackerlibrary.export.TrackerPDF; import de.domjos.unitrackerlibrary.export.TrackerXML; import de.domjos.unitrackerlibrary.interfaces.IBugService; +import de.domjos.unitrackerlibrary.model.issues.Issue; +import de.domjos.unitrackerlibrary.model.projects.Version; public final class ExportTask extends AbstractTask { private String path, xslt; private TrackerXML.Type type; - private Object project_id; + private Object project_id, version_id; private byte[] array, icon; public ExportTask(Activity activity, IBugService bugService, TrackerXML.Type type, Object project_id, String path, boolean showNotifications, int icon, byte[] array, byte[] appIcon, String xslt) { + this(activity, bugService, type, project_id, path, showNotifications, icon, array, appIcon, xslt, null); + } + + public ExportTask(Activity activity, IBugService bugService, TrackerXML.Type type, Object project_id, String path, boolean showNotifications, int icon, byte[] array, byte[] appIcon, String xslt, Object versionId) { super(activity, bugService, R.string.task_export_title, R.string.task_export_contet, showNotifications, icon); this.path = path; this.type = type; @@ -43,6 +49,7 @@ public ExportTask(Activity activity, IBugService bugService, TrackerXML.Type typ this.array = array; this.icon = appIcon; this.xslt = xslt; + this.version_id = versionId; } @Override @@ -54,24 +61,40 @@ protected void before() { @SuppressWarnings("unchecked") protected Void doInBackground(Object... objects) { try { - String[] splPath = this.path.split("\\."); - String extension = splPath[splPath.length - 1]; - List objectList = Arrays.asList(objects); + if(this.version_id == null) { + List objectList = Arrays.asList(objects); + String[] splPath = this.path.split("\\."); + String extension = splPath[splPath.length - 1]; + + switch (extension.trim().toLowerCase()) { + case "xml": + TrackerXML buggerXML = new TrackerXML(super.bugService, this.type, this.project_id, objectList, this.path, this.xslt); + buggerXML.doExport(); + break; + case "txt": + case "csv": + TrackerCSV buggerCSV = new TrackerCSV(super.bugService, this.type, this.project_id, objectList, this.path); + buggerCSV.doExport(); + break; + case "pdf": + TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, objectList, this.path, this.array, this.icon); + buggerPDF.doExport(); + break; + } + } else { + List issues = super.bugService.getIssues(super.returnTemp(this.project_id)); + for(int i = 0; i<=issues.size()-1; i++) { + issues.set(i, super.bugService.getIssue(issues.get(i).getId(), super.returnTemp(project_id))); + } - switch (extension.trim().toLowerCase()) { - case "xml": - TrackerXML buggerXML = new TrackerXML(super.bugService, this.type, this.project_id, objectList, this.path, this.xslt); - buggerXML.doExport(); - break; - case "txt": - case "csv": - TrackerCSV buggerCSV = new TrackerCSV(super.bugService, this.type, this.project_id, objectList, this.path); - buggerCSV.doExport(); - break; - case "pdf": - TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, objectList, this.path, this.array, this.icon); - buggerPDF.doExport(); - break; + List versions = super.bugService.getVersions("versions", super.returnTemp(this.project_id)); + TrackerPDF buggerPDF = new TrackerPDF(super.bugService, this.type, this.project_id, issues, this.path, this.array, this.icon); + for(Version current : versions) { + if(current.getId().equals(this.version_id)) { + buggerPDF.createChangeLog(current); + break; + } + } } } catch (Exception ex) { super.printException(ex);