mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
code cleanup
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<CommentEntity> replies;
|
||||
|
||||
public CommentTree(CommentEntity rootComment) {
|
||||
this.rootComment = rootComment;
|
||||
this.replies = new ArrayList<CommentEntity>();
|
||||
}
|
||||
|
||||
public CommentEntity getRootComment() {
|
||||
return rootComment;
|
||||
}
|
||||
|
||||
public List<CommentEntity> getReplies() {
|
||||
return replies;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.diylc.plugins.cloud.model;
|
||||
|
||||
public class CountryDetails {
|
||||
|
||||
private String country;
|
||||
private String details;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.diylc.plugins.cloud.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DashboardEntity {
|
||||
|
||||
private List<ProjectEntity> latestProjects;
|
||||
private List<ProjectEntity> mostDownloadedProjects;
|
||||
private List<UserEntity> topContributors;
|
||||
private List<CountryDetails> contributorsByCountry;
|
||||
private List<CountryDetails> visitorsByCountry;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<ProjectEntity> 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<CommentEntity> getComments(int projectId) throws CloudException {
|
||||
LOG.info("Fetching comments for projectId: " + projectId);
|
||||
try {
|
||||
Object res = getService().getComments(projectId);
|
||||
if (res == null)
|
||||
|
||||
@@ -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<ProjectEntity> currentResults;
|
||||
|
||||
public PagingProvider(CloudPresenter cloudPresenter) {
|
||||
this(cloudPresenter, 10);
|
||||
}
|
||||
|
||||
public PagingProvider(CloudPresenter cloudPresenter, int itemsPerPage) {
|
||||
this.cloudPresenter = cloudPresenter;
|
||||
this.itemsPerPage = itemsPerPage;
|
||||
}
|
||||
|
||||
public List<ProjectEntity> startSession(String searchFor, String category, String sort) throws CloudException {
|
||||
|
||||
Reference in New Issue
Block a user