From 94c8512c11eedb4aa4b3222a728b4ae7e3d74f84 Mon Sep 17 00:00:00 2001 From: bancika Date: Tue, 1 Nov 2016 16:43:24 +0100 Subject: [PATCH] code cleanup --- .../plugins/cloud/model/CommentEntity.java | 5 ++++ .../plugins/cloud/model/CommentTree.java | 23 ----------------- .../plugins/cloud/model/CountryDetails.java | 7 ------ .../plugins/cloud/model/DashboardEntity.java | 12 --------- .../plugins/cloud/model/IServiceAPI.java | 2 +- .../plugins/cloud/model/ProjectEntity.java | 14 ++++++++--- .../diylc/plugins/cloud/model/UserEntity.java | 5 ++++ .../cloud/presenter/CloudPresenter.java | 25 ++++++++++++++++--- .../cloud/presenter/PagingProvider.java | 13 ++++++---- .../plugins/cloud/view/CommentDialog.java | 17 +++++++++---- .../plugins/cloud/view/UserEditDialog.java | 4 ++- .../cloud/view/browser/CloudBrowserFrame.java | 5 ++++ .../view/browser/ResultsScrollPanel.java | 8 ++++++ 13 files changed, 78 insertions(+), 62 deletions(-) delete mode 100644 diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentTree.java delete mode 100644 diylc/diylc-core/src/org/diylc/plugins/cloud/model/CountryDetails.java delete mode 100644 diylc/diylc-core/src/org/diylc/plugins/cloud/model/DashboardEntity.java diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java index fc6363d0..c61284c4 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java @@ -2,6 +2,11 @@ package org.diylc.plugins.cloud.model; import java.io.Serializable; +/** + * Represents a single post in the comment section of a cloud project. + * + * @author Branislav Stojkovic + */ public class CommentEntity implements Serializable { private static final long serialVersionUID = 1L; diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentTree.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentTree.java deleted file mode 100644 index 12c7c0f0..00000000 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentTree.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.diylc.plugins.cloud.model; - -import java.util.ArrayList; -import java.util.List; - -public class CommentTree { - - private CommentEntity rootComment; - private List replies; - - public CommentTree(CommentEntity rootComment) { - this.rootComment = rootComment; - this.replies = new ArrayList(); - } - - public CommentEntity getRootComment() { - return rootComment; - } - - public List getReplies() { - return replies; - } -} diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CountryDetails.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CountryDetails.java deleted file mode 100644 index db917740..00000000 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CountryDetails.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.diylc.plugins.cloud.model; - -public class CountryDetails { - - private String country; - private String details; -} diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/DashboardEntity.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/DashboardEntity.java deleted file mode 100644 index 30f314c2..00000000 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/DashboardEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.diylc.plugins.cloud.model; - -import java.util.List; - -public class DashboardEntity { - - private List latestProjects; - private List mostDownloadedProjects; - private List topContributors; - private List contributorsByCountry; - private List visitorsByCountry; -} diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java index 2f7614ed..94a4bc3d 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java @@ -8,7 +8,7 @@ import com.diyfever.httpproxy.ParamName; /*** * Interface of DIYLC PHP server located at www.diy-fever.com/diylc/api/v1 * - * @author bancika + * @author Branislav Stojkovic * */ public interface IServiceAPI { diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/ProjectEntity.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/ProjectEntity.java index 291a63ca..0c017a25 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/ProjectEntity.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/ProjectEntity.java @@ -4,6 +4,11 @@ import java.io.Serializable; import org.diylc.core.annotations.EditableProperty; +/** + * Represents a cloud project object, identified by {@link ProjectEntity#id}. + * + * @author Branislav Stojkovic + */ public class ProjectEntity implements Serializable { private static final long serialVersionUID = 1L; @@ -60,7 +65,7 @@ public class ProjectEntity implements Serializable { public void setOwner(String owner) { this.owner = owner; } - + public String getCategory() { return category; } @@ -68,12 +73,13 @@ public class ProjectEntity implements Serializable { public void setCategory(String category) { this.category = category; } - - @EditableProperty(defaultable = false, sortOrder = 2, additionalOptions = EditableProperty.DYNAMIC_LIST + "getCategories") + + @EditableProperty(defaultable = false, sortOrder = 2, additionalOptions = EditableProperty.DYNAMIC_LIST + + "getCategories") public String getCategoryForDisplay() { return categoryForDisplay; } - + public void setCategoryForDisplay(String categoryForDisplay) { this.categoryForDisplay = categoryForDisplay; } diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/UserEntity.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/UserEntity.java index 65b23574..591405b1 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/UserEntity.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/UserEntity.java @@ -2,6 +2,11 @@ package org.diylc.plugins.cloud.model; import java.io.Serializable; +/** + * Represents cloud user details. + * + * @author Branislav Stojkovic + */ public class UserEntity implements Serializable { private static final long serialVersionUID = 1L; diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java index 2dd7c8b2..0aaf4ecc 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java @@ -24,6 +24,11 @@ import org.diylc.presenter.ComponentProcessor; import com.diyfever.httpproxy.PhpFlatProxy; import com.diyfever.httpproxy.ProxyFactory; +/** + * Contains all the back-end logic for using the cloud and manipulating projects on the cloud. + * + * @author Branislav Stojkovic + */ public class CloudPresenter { private static String USERNAME_KEY = "cloud.Username"; @@ -119,6 +124,7 @@ public class CloudPresenter { public String[] getCategories() throws CloudException { if (categories == null) { Object res; + LOG.info("Fetching categories"); try { res = getService().getCategories(); if (res != null && res.equals(ERROR)) @@ -146,6 +152,7 @@ public class CloudPresenter { if (username == null || token == null) throw new CloudException("Login failed. Please try to login again."); + LOG.info("Uploading a new project: " + projectName); try { String res = getService().uploadProject(username, token, getMachineId(), projectName, category, description, diylcVersion, @@ -163,11 +170,12 @@ public class CloudPresenter { if (username == null || token == null) throw new CloudException("Login failed. Please try to login again."); - + LOG.info("Updating project with projectId: " + project.getId()); try { String res = - getService().uploadProject(username, token, getMachineId(), project.getName(), project.getCategoryForDisplay(), - project.getDescription(), diylcVersion, project.getKeywords(), null, null, project.getId()); + getService().uploadProject(username, token, getMachineId(), project.getName(), + project.getCategoryForDisplay(), project.getDescription(), diylcVersion, project.getKeywords(), null, + null, project.getId()); if (!res.equals(SUCCESS)) throw new CloudException(res); } catch (Exception e) { @@ -182,6 +190,7 @@ public class CloudPresenter { if (username == null || token == null) throw new CloudException("Login failed. Please try to login again."); + LOG.info("Deleting project with projectId: " + projectId); try { String res = getService().deleteProject(username, token, getMachineId(), projectId); if (!res.equals(SUCCESS)) @@ -198,6 +207,8 @@ public class CloudPresenter { if (username == null || token == null) throw new CloudException("Login failed. Please try to login again."); + LOG.info("Posting a new comment to projectId: " + projectId); + try { String res = getService().postComment(username, token, getMachineId(), projectId, comment); if (!res.equals(SUCCESS)) @@ -209,6 +220,7 @@ public class CloudPresenter { public void createUserAccount(String username, String password, String email, String website, String bio) throws CloudException { + LOG.info("Creating a new user: " + username); try { String res = getService().createUser(username, password, email, website, bio); if (res == null) @@ -223,7 +235,7 @@ public class CloudPresenter { public UserEntity getUserDetails() throws CloudException { String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null); String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null); - + LOG.info("Retreiving user details for: " + username); Object res; try { res = getService().getUserDetails(username, token, getMachineId()); @@ -244,6 +256,7 @@ public class CloudPresenter { public void updatePassword(String oldPassword, String newPassword) throws CloudException { String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null); + LOG.info("Updating password for: " + username); String res; try { res = getService().updatePassword(username, oldPassword, newPassword); @@ -258,6 +271,7 @@ public class CloudPresenter { String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null); String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null); + LOG.info("Updating user details for: " + username); String res; try { res = getService().updateUserDetails(username, token, getMachineId(), email, website, bio); @@ -283,6 +297,7 @@ public class CloudPresenter { public List fetchUserUploads(Integer projectId) throws CloudException { UserEntity user = getUserDetails(); + LOG.info("Fetching all user uploads for: " + user.getUsername()); try { Object res = getService().search("", "", 1, Integer.MAX_VALUE, getSortings()[0], user.getUsername(), projectId); return processResults(res); @@ -322,6 +337,7 @@ public class CloudPresenter { } public String[] getSortings() throws CloudException { + LOG.info("Fetching sortings"); try { return getService().getSortings().toArray(new String[0]); } catch (Exception e) { @@ -330,6 +346,7 @@ public class CloudPresenter { } public List getComments(int projectId) throws CloudException { + LOG.info("Fetching comments for projectId: " + projectId); try { Object res = getService().getComments(projectId); if (res == null) diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/PagingProvider.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/PagingProvider.java index a243f58d..ef9ebeeb 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/PagingProvider.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/PagingProvider.java @@ -4,6 +4,14 @@ import java.util.List; import org.diylc.plugins.cloud.model.ProjectEntity; +/** + * Used to create paging of the search results. Use + * {@link PagingProvider#startSession(String, String, String)} to start the search session and then + * {@link PagingProvider#hasMoreData()} returns true if there's more data available and + * {@link PagingProvider#requestMoreData()} returns the next page. + * + * @author Branislav Stojkovic + */ public class PagingProvider { private CloudPresenter cloudPresenter; @@ -17,12 +25,7 @@ public class PagingProvider { private List currentResults; public PagingProvider(CloudPresenter cloudPresenter) { - this(cloudPresenter, 10); - } - - public PagingProvider(CloudPresenter cloudPresenter, int itemsPerPage) { this.cloudPresenter = cloudPresenter; - this.itemsPerPage = itemsPerPage; } public List startSession(String searchFor, String category, String sort) throws CloudException { diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/CommentDialog.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/CommentDialog.java index 844c1728..58df4b20 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/CommentDialog.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/CommentDialog.java @@ -26,6 +26,12 @@ import org.diylc.plugins.cloud.presenter.CloudPresenter; import org.diylc.swing.ISimpleView; import org.diylc.swing.gui.components.HTMLTextArea; +/** + * {@link JDialog} that shows a list of comments posted to a cloud project and provides controls for + * posting more comments. + * + * @author Branislav Stojkovic + */ public class CommentDialog extends JDialog { private static final String JUST_NOW = "just now"; @@ -45,7 +51,7 @@ public class CommentDialog extends JDialog { private int lastPosition = 0; - private ISimpleView owner; + private ISimpleView cloudUI; public CommentDialog(ISimpleView cloudUI, ProjectEntity project, List comments, CloudPresenter presenter) { @@ -53,6 +59,7 @@ public class CommentDialog extends JDialog { this.project = project; this.comments = comments; this.presenter = presenter; + this.cloudUI = cloudUI; setMinimumSize(new Dimension(400, 600)); setContentPane(getMainPanel()); pack(); @@ -69,7 +76,7 @@ public class CommentDialog extends JDialog { if (listPanel == null) { listPanel = new JPanel(new GridBagLayout()); listPanel.setBackground(Color.white); - for (CommentEntity c : comments) { + for (CommentEntity c : comments) { addComment(c); GridBagConstraints gbc = new GridBagConstraints(); @@ -135,9 +142,9 @@ public class CommentDialog extends JDialog { public void actionPerformed(ActionEvent e) { final String comment = getReplyArea().getText(); if (comment.trim().length() == 0) - owner.showMessage("Cannot post an empty comment.", "Cloud Error", IView.ERROR_MESSAGE); + cloudUI.showMessage("Cannot post an empty comment.", "Cloud Error", IView.ERROR_MESSAGE); - owner.executeBackgroundTask(new ITask() { + cloudUI.executeBackgroundTask(new ITask() { @Override public Void doInBackground() throws Exception { @@ -147,7 +154,7 @@ public class CommentDialog extends JDialog { @Override public void failed(Exception e) { - owner.showMessage("Error posting comment.", "Cloud Error", IView.ERROR_MESSAGE); + cloudUI.showMessage("Error posting comment.", "Cloud Error", IView.ERROR_MESSAGE); } @Override diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/UserEditDialog.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/UserEditDialog.java index bc6ffd93..675b4577 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/UserEditDialog.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/UserEditDialog.java @@ -12,6 +12,7 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; +import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; @@ -128,7 +129,8 @@ public class UserEditDialog extends ButtonDialog { mainPanel.add(getWebsiteField(), gbc); gbc.gridy = 5; - mainPanel.add(getBioArea(), gbc); + gbc.fill = GridBagConstraints.BOTH; + mainPanel.add(new JScrollPane(getBioArea()), gbc); } return mainPanel; } diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java index 88124e2f..47d208cc 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java @@ -32,6 +32,11 @@ import org.diylc.swing.ISimpleView; import org.diylc.swing.ISwingUI; import org.diylc.utils.Pair; +/** + * {@link JFrame} for searching the projects on the cloud. + * + * @author Branislav Stojkovic + */ public class CloudBrowserFrame extends JFrame implements ISimpleView { private static final String TITLE = "Search The Cloud"; diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java index c201a4fb..274ecdf0 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java @@ -55,6 +55,14 @@ import org.diylc.swing.plugins.cloud.view.UploadDialog; import org.diylc.swing.plugins.file.FileFilterEnum; import org.diylc.swingframework.ButtonDialog; +/** + * Component that is capable of showing a list of {@link ProjectEntity} objects. Can work in paging + * mode and pull one page of data at a time. + * + * @see {@link PagingProvider} + * + * @author Branislav Stojkovic + */ public class ResultsScrollPanel extends JScrollPane { private static final long serialVersionUID = 1L;