mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +10:00
refactor drop down button to avoid 3 libs
service API
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/http-proxy.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
Binary file not shown.
+185
@@ -0,0 +1,185 @@
|
||||
package org.diylc.swing.plugins.online.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ProjectEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String owner;
|
||||
private String category;
|
||||
private String updated;
|
||||
private String thumbnailUrl;
|
||||
private String downloadUrl;
|
||||
|
||||
public ProjectEntity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProjectEntity(int id, String name, String description, String owner,
|
||||
String category, String updated, String thumbnailUrl,
|
||||
String downloadUrl) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.owner = owner;
|
||||
this.category = category;
|
||||
this.updated = updated;
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(String updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public String getThumbnailUrl() {
|
||||
return thumbnailUrl;
|
||||
}
|
||||
|
||||
public void setThumbnailUrl(String thumbnailUrl) {
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
public void setDownloadUrl(String downloadUrl) {
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
|
||||
// public Action getDownload() {
|
||||
//
|
||||
// Action a = new AbstractAction() {
|
||||
//
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// JOptionPane.showMessageDialog(null, name);
|
||||
// }
|
||||
// };
|
||||
// a.putValue(AbstractAction.NAME, "Download");
|
||||
// return a;
|
||||
// }
|
||||
//
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((category == null) ? 0 : category.hashCode());
|
||||
result = prime * result
|
||||
+ ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result
|
||||
+ ((downloadUrl == null) ? 0 : downloadUrl.hashCode());
|
||||
result = prime * result + id;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
||||
result = prime * result
|
||||
+ ((thumbnailUrl == null) ? 0 : thumbnailUrl.hashCode());
|
||||
result = prime * result + ((updated == null) ? 0 : updated.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ProjectEntity other = (ProjectEntity) obj;
|
||||
if (category == null) {
|
||||
if (other.category != null)
|
||||
return false;
|
||||
} else if (!category.equals(other.category))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (downloadUrl == null) {
|
||||
if (other.downloadUrl != null)
|
||||
return false;
|
||||
} else if (!downloadUrl.equals(other.downloadUrl))
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (owner == null) {
|
||||
if (other.owner != null)
|
||||
return false;
|
||||
} else if (!owner.equals(other.owner))
|
||||
return false;
|
||||
if (thumbnailUrl == null) {
|
||||
if (other.thumbnailUrl != null)
|
||||
return false;
|
||||
} else if (!thumbnailUrl.equals(other.thumbnailUrl))
|
||||
return false;
|
||||
if (updated == null) {
|
||||
if (other.updated != null)
|
||||
return false;
|
||||
} else if (!updated.equals(other.updated))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + " by " + owner + " updated on " + updated;
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package org.diylc.swing.plugins.online.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import com.diyfever.httpproxy.ParamName;
|
||||
|
||||
/***
|
||||
* Interface of DIYLC PHP server located at www.diy-fever.com/diylc/api
|
||||
*
|
||||
* @author bancika
|
||||
*
|
||||
*/
|
||||
public interface ServiceAPI {
|
||||
|
||||
public static final String URL_KEY = "serviceUrl";
|
||||
|
||||
/**
|
||||
* Creates a user with the specified details.
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @param email
|
||||
* @param website
|
||||
* @param bio
|
||||
* @return "Success" if the operation is successful or error message if it
|
||||
* failed.
|
||||
*/
|
||||
String createUser(@ParamName("username") String username,
|
||||
@ParamName("password") String password,
|
||||
@ParamName("email") String email,
|
||||
@ParamName("website") String website, @ParamName("bio") String bio);
|
||||
|
||||
/***
|
||||
* Updates user details using token to authenticate.
|
||||
*
|
||||
* @param username
|
||||
* @param token
|
||||
* @param machineId
|
||||
* @param email
|
||||
* @param website
|
||||
* @param bio
|
||||
* @return "Success" if the operation is successful or error message if it
|
||||
* failed.
|
||||
*/
|
||||
String updateUser(@ParamName("username") String username,
|
||||
@ParamName("token") String token,
|
||||
@ParamName("machineId") String machineId,
|
||||
@ParamName("email") String email,
|
||||
@ParamName("website") String website, @ParamName("bio") String bio);
|
||||
|
||||
/***
|
||||
* Tries to login with the provided credentials and machineId.
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @param machineId
|
||||
* @return login token if the login was successful or string literal "Error"
|
||||
* if it failed.
|
||||
*/
|
||||
String login(@ParamName("username") String username,
|
||||
@ParamName("password") String password,
|
||||
@ParamName("machineId") String machineId);
|
||||
|
||||
/***
|
||||
* Tries to authenticate with the token that was previously created by
|
||||
* calling login() function.
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
* @param machineId
|
||||
* @return "Success" if the login is successful or error message if it
|
||||
* failed.
|
||||
*/
|
||||
String loginWithToken(@ParamName("username") String username,
|
||||
@ParamName("token") String token,
|
||||
@ParamName("machineId") String machineId);
|
||||
|
||||
/***
|
||||
* Searches for projects that meet the specified search criteria. Supports
|
||||
* pagination.
|
||||
*
|
||||
* @param criteria
|
||||
* @param category
|
||||
* @param format
|
||||
* @param page
|
||||
* @param itemsPerPage
|
||||
* @param sort
|
||||
* @return string with error message if the error occurred or a list of
|
||||
* {@link ProjectEntity} objects.
|
||||
*/
|
||||
Object search(@ParamName("criteria") String criteria,
|
||||
@ParamName("category") String category,
|
||||
@ParamName("format") String format,
|
||||
@ParamName("page") Integer page,
|
||||
@ParamName("itemsPerPage") Integer itemsPerPage,
|
||||
@ParamName("sort") String sort);
|
||||
|
||||
/**
|
||||
* Uploads a project using token to authenticate.
|
||||
*
|
||||
* @param username
|
||||
* @param token
|
||||
* @param machineId
|
||||
* @param projectName
|
||||
* @param category
|
||||
* @param description
|
||||
* @param diylcVersion
|
||||
* @param keywords
|
||||
* @param thumbnail
|
||||
* @param project
|
||||
* @return "Success" if the upload was successful or error message if it
|
||||
* failed.
|
||||
*/
|
||||
String upload(@ParamName("username") String username,
|
||||
@ParamName("token") String token,
|
||||
@ParamName("machineId") String machineId,
|
||||
@ParamName("projectName") String projectName,
|
||||
@ParamName("category") String category,
|
||||
@ParamName("description") String description,
|
||||
@ParamName("diylcVersion") String diylcVersion,
|
||||
@ParamName("keywords") String keywords,
|
||||
@ParamName("thumbnail") File thumbnail,
|
||||
@ParamName("project") File project);
|
||||
|
||||
/**
|
||||
* @return a {@link List} of available categories.
|
||||
*/
|
||||
List<String> getCategories();
|
||||
|
||||
/**
|
||||
* @return a {@link List} of available sortings.
|
||||
*/
|
||||
List<String> getAvailableSortings();
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package org.diylc.swing.plugins.online.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class UserEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int id;
|
||||
private String userName;
|
||||
private String password;
|
||||
private String email;
|
||||
private String website;
|
||||
private String bio;
|
||||
|
||||
public UserEntity(int id, String userName, String password, String email,
|
||||
String website, String bio) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.website = website;
|
||||
this.bio = bio;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getWebsite() {
|
||||
return website;
|
||||
}
|
||||
|
||||
public void setWebsite(String website) {
|
||||
this.website = website;
|
||||
}
|
||||
|
||||
public String getBio() {
|
||||
return bio;
|
||||
}
|
||||
|
||||
public void setBio(String bio) {
|
||||
this.bio = bio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((bio == null) ? 0 : bio.hashCode());
|
||||
result = prime * result + ((email == null) ? 0 : email.hashCode());
|
||||
result = prime * result + id;
|
||||
result = prime * result
|
||||
+ ((password == null) ? 0 : password.hashCode());
|
||||
result = prime * result
|
||||
+ ((userName == null) ? 0 : userName.hashCode());
|
||||
result = prime * result + ((website == null) ? 0 : website.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
UserEntity other = (UserEntity) obj;
|
||||
if (bio == null) {
|
||||
if (other.bio != null)
|
||||
return false;
|
||||
} else if (!bio.equals(other.bio))
|
||||
return false;
|
||||
if (email == null) {
|
||||
if (other.email != null)
|
||||
return false;
|
||||
} else if (!email.equals(other.email))
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (password == null) {
|
||||
if (other.password != null)
|
||||
return false;
|
||||
} else if (!password.equals(other.password))
|
||||
return false;
|
||||
if (userName == null) {
|
||||
if (other.userName != null)
|
||||
return false;
|
||||
} else if (!userName.equals(other.userName))
|
||||
return false;
|
||||
if (website == null) {
|
||||
if (other.website != null)
|
||||
return false;
|
||||
} else if (!website.equals(other.website))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserEntity [userName=" + userName + "]";
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
|
||||
public class DIYLCServiceException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
|
||||
public class NotConnectedException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
|
||||
public class NotExistsException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NotExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
|
||||
public class NotLoggedInException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.swing.plugins.online.model.ServiceAPI;
|
||||
|
||||
import com.diyfever.httpproxy.PhpFlatProxy;
|
||||
import com.diyfever.httpproxy.ProxyFactory;
|
||||
|
||||
public class OnlinePresenter {
|
||||
|
||||
private final static Logger LOG = Logger.getLogger(OnlinePresenter.class);
|
||||
|
||||
private ServiceAPI service;
|
||||
private String serviceUrl;
|
||||
private String machineId;
|
||||
|
||||
public OnlinePresenter() {
|
||||
serviceUrl = ConfigurationManager.getInstance().readString(
|
||||
ServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api");
|
||||
ProxyFactory factory = new ProxyFactory(new PhpFlatProxy());
|
||||
service = factory.createProxy(ServiceAPI.class, serviceUrl);
|
||||
}
|
||||
|
||||
public boolean login(String username, String password) {
|
||||
String res = service.login(username, password, getMachineId());
|
||||
if (res.equals("Error"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMachineId() {
|
||||
if (machineId == null) {
|
||||
try {
|
||||
InetAddress ip = InetAddress.getLocalHost();
|
||||
|
||||
NetworkInterface network = NetworkInterface
|
||||
.getByInetAddress(ip);
|
||||
|
||||
byte[] mac = network.getHardwareAddress();
|
||||
|
||||
StringBuilder sb = new StringBuilder(18);
|
||||
for (byte b : mac) {
|
||||
if (sb.length() > 0)
|
||||
sb.append(':');
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
|
||||
machineId = sb.toString();
|
||||
} catch (Exception e) {
|
||||
machineId = "Generic";
|
||||
}
|
||||
}
|
||||
return machineId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user