diff --git a/sachith_task/README.txt b/sachith_task/README.txt new file mode 100644 index 0000000..5914cf7 --- /dev/null +++ b/sachith_task/README.txt @@ -0,0 +1,3 @@ +Here I have commit that android mobile task and RESTful api which was developed, little time ago. That has use of Jersey framework and hibernate. + +In the mobile applicaion I used a jersey client as the rest client. No deletion operation has developed. I used Android file management api for data store management. \ No newline at end of file diff --git a/sachith_task/RESTSource/pom.xml b/sachith_task/RESTSource/pom.xml new file mode 100644 index 0000000..489ad59 --- /dev/null +++ b/sachith_task/RESTSource/pom.xml @@ -0,0 +1,115 @@ + + + 4.0.0 + + com.blackhat + Blackhat + 2.0-SNAPSHOT + war + + Blackhat + + + ${project.build.directory}/endorsed + UTF-8 + + + + + org.hibernate + hibernate-entitymanager + 4.3.1.Final + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + + + javax + javaee-web-api + 7.0 + provided + + + org.glassfish.jersey.containers + jersey-container-servlet + 2.22.1 + provided + + + + + log4j + log4j + 1.2.17 + + + org.testng + testng + 6.1.1 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + ${endorsed.dir} + + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + false + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.6 + + + validate + + copy + + + ${endorsed.dir} + true + + + javax + javaee-endorsed-api + 7.0 + jar + + + + + + + + + + + unknown-jars-temp-repo + A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository. + file:${project.basedir}/lib + + + diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/BlackhatConstants.java b/sachith_task/RESTSource/src/main/java/com/blackhat/BlackhatConstants.java new file mode 100644 index 0000000..3e55271 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/BlackhatConstants.java @@ -0,0 +1,18 @@ +package com.blackhat; + +import javax.servlet.ServletContext; +import org.hibernate.Session; +import org.hibernate.SessionFactory; + +/** + * + * @author Sachith Dickwella + */ +public abstract class BlackhatConstants { + + public static String SESSION_FACTORY = "SessionFactory"; + + public static final Session getSession(ServletContext sc) { + return ((SessionFactory) sc.getAttribute(SESSION_FACTORY)).openSession(); + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Artwork.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Artwork.java new file mode 100644 index 0000000..c6a6437 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Artwork.java @@ -0,0 +1,218 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllArtworks", query = "from Artwork a"), + @NamedQuery(name = "getArtworkById", query = "from Artwork a where a.id = :id")}) +@Entity +@Table(name = "Artwork", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"}), + @UniqueConstraint(columnNames = "REFERENCE_NO")}) +public class Artwork implements Serializable { + + private static final long serialVersionUID = -2208323497507122994L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "JOB_ID", referencedColumnName = "ID") + private SampleJob jobId; + + @NotNull + @Column(name = "REFERENCE_NO", length = 30) + private String referenceNumber; + + @NotNull + @Column(name = "STATUS") + private char status; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + @Column(name = "QC_USER", length = 30) + private String qcUser; + + @Temporal(TemporalType.DATE) + @Column(name = "QC_DATETIME") + private Date qcDateTime; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the jobId + */ + public SampleJob getJobId() { + return jobId; + } + + /** + * @param jobId the jobId to set + */ + public void setJobId(SampleJob jobId) { + this.jobId = jobId; + } + + /** + * @return the referenceNumber + */ + public String getReferenceNumber() { + return referenceNumber; + } + + /** + * @param referenceNumber the referenceNumber to set + */ + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + /** + * @return the status + */ + public char getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(char status) { + this.status = status; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } + + /** + * @return the qcUser + */ + public String getQcUser() { + return qcUser; + } + + /** + * @param qcUser the qcUser to set + */ + public void setQcUser(String qcUser) { + this.qcUser = qcUser; + } + + /** + * @return the qcDateTime + */ + public Date getQcDateTime() { + return qcDateTime; + } + + /** + * @param qcDateTime the qcDateTime to set + */ + public void setQcDateTime(Date qcDateTime) { + this.qcDateTime = qcDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Credential.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Credential.java new file mode 100644 index 0000000..f7b1d01 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Credential.java @@ -0,0 +1,159 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllCredentials", query = "from Credential c"), + @NamedQuery(name = "getCredentialByUserName", query = "from Credential c where c.userName = :userName")}) +@Entity +@Table(name = "Credential", uniqueConstraints = { + @UniqueConstraint(columnNames = {"USER_NAME"})}) +public class Credential implements Serializable { + + private static final long serialVersionUID = 8834121503936150791L; + + @Id + @NotNull + @Column(name = "USER_NAME", length = 30) + private String userName; + + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "userName") + private User user; + + @NotNull + @Column(name = "PASSWORD", length = 75) + private String password; + + @NotNull + @Column(name = "STATUS", length = 1) + private char status; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + @Temporal(TemporalType.DATE) + @Column(name = "LASTLOGIN_DATETIME") + private Date lastLoginDateTime; + + /** + * @return the userName + */ + public String getUserName() { + return userName; + } + + /** + * @param userName the userName to set + */ + public void setUserName(String userName) { + this.userName = userName; + } + + /** + * @return the user + */ + public User getUser() { + return user; + } + + /** + * @param user the user to set + */ + public void setUser(User user) { + this.user = user; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * @return the status + */ + public char getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(char status) { + this.status = status; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } + + /** + * @return the lastLoginDateTime + */ + public Date getLastLoginDateTime() { + return lastLoginDateTime; + } + + /** + * @param lastLoginDateTime the lastLoginDateTime to set + */ + public void setLastLoginDateTime(Date lastLoginDateTime) { + this.lastLoginDateTime = lastLoginDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Customer.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Customer.java new file mode 100644 index 0000000..9163f5c --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Customer.java @@ -0,0 +1,254 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllCustomers", query = "from Customer c"), + @NamedQuery(name = "getCustomerById", query = "from Customer c where c.id = :id"), + @NamedQuery(name = "getCustomerByName", query = "from Customer c where lower(c.name) like lower(:name)")}) +@Entity +@Table(name = "Customer", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"})}) +public class Customer implements Serializable { + + private static final long serialVersionUID = -7502123462486867833L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @NotNull + @Column(name = "NAME", length = 100) + private String name; + + @NotNull + @Column(name = "ADDRESS_LINE1", length = 40) + private String addressLine1; + + @Column(name = "ADDRESS_LINE2", length = 40) + private String addressLine2; + + @NotNull + @Column(name = "CITY_TOWN", length = 30) + private String cityTown; + + @NotNull + @Column(name = "CONTACT_PERSON", length = 100) + private String contactPerson; + + @NotNull + @Column(name = "TELEPHONE_NO", length = 20) + private String telephoneNo; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "customerId") + private List orders; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the addressLine1 + */ + public String getAddressLine1() { + return addressLine1; + } + + /** + * @param addressLine1 the addressLine1 to set + */ + public void setAddressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + } + + /** + * @return the addressLine2 + */ + public String getAddressLine2() { + return addressLine2; + } + + /** + * @param addressLine2 the addressLine2 to set + */ + public void setAddressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + } + + /** + * @return the cityTown + */ + public String getCityTown() { + return cityTown; + } + + /** + * @param cityTown the cityTown to set + */ + public void setCityTown(String cityTown) { + this.cityTown = cityTown; + } + + /** + * @return the contactPerson + */ + public String getContactPerson() { + return contactPerson; + } + + /** + * @param contactPerson the contactPerson to set + */ + public void setContactPerson(String contactPerson) { + this.contactPerson = contactPerson; + } + + /** + * @return the telephoneNo + */ + public String getTelephoneNo() { + return telephoneNo; + } + + /** + * @param telephoneNo the telephoneNo to set + */ + public void setTelephoneNo(String telephoneNo) { + this.telephoneNo = telephoneNo; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } + + /** + * @return the orders + */ + public List getOrders() { + return orders; + } + + /** + * @param orders the orders to set + */ + public void setOrders(List orders) { + this.orders = orders; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/DeliveryAddress.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/DeliveryAddress.java new file mode 100644 index 0000000..ba54b59 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/DeliveryAddress.java @@ -0,0 +1,233 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllDeliveryAddresses", query = "from DeliveryAddress d"), + @NamedQuery(name = "getDeliveryAddressById", query = "from DeliveryAddress d where d.id = :id")}) +@Entity +@Table(name = "DeliveryAddress", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"})}) +public class DeliveryAddress implements Serializable { + + private static final long serialVersionUID = -9092229007232139499L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "JOB_ID", referencedColumnName = "ID") + private SampleJob jobId; + + @NotNull + @Column(name = "ADDRESS_LINE1", length = 40) + private String addressLine1; + + @Column(name = "ADDRESS_LINE2", length = 40) + private String addressLine2; + + @NotNull + @Column(name = "CITY_TOWN", length = 30) + private String cityTown; + + @Column(name = "STATE_PROVINCE", length = 50) + private String stateProvince; + + @Column(name = "ZIP_CODE", length = 10) + private String zipCode; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the jobId + */ + public SampleJob getJobId() { + return jobId; + } + + /** + * @param jobId the jobId to set + */ + public void setJobId(SampleJob jobId) { + this.jobId = jobId; + } + + /** + * @return the addressLine1 + */ + public String getAddressLine1() { + return addressLine1; + } + + /** + * @param addressLine1 the addressLine1 to set + */ + public void setAddressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + } + + /** + * @return the addressLine2 + */ + public String getAddressLine2() { + return addressLine2; + } + + /** + * @param addressLine2 the addressLine2 to set + */ + public void setAddressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + } + + /** + * @return the cityTown + */ + public String getCityTown() { + return cityTown; + } + + /** + * @param cityTown the cityTown to set + */ + public void setCityTown(String cityTown) { + this.cityTown = cityTown; + } + + /** + * @return the stateProvince + */ + public String getStateProvince() { + return stateProvince; + } + + /** + * @param stateProvince the stateProvince to set + */ + public void setStateProvince(String stateProvince) { + this.stateProvince = stateProvince; + } + + /** + * @return the zipCode + */ + public String getZipCode() { + return zipCode; + } + + /** + * @param zipCode the zipCode to set + */ + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/JobOrder.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/JobOrder.java new file mode 100644 index 0000000..a0d4250 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/JobOrder.java @@ -0,0 +1,185 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllJobOrders", query = "from JobOrder j"), + @NamedQuery(name = "getJobOrderById", query = "from JobOrder j where j.id = :id")}) +@Entity +@Table(name = "JobOrder", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"}), + @UniqueConstraint(columnNames = {"REFERENCE_NO"})}) +public class JobOrder implements Serializable { + + private static final long serialVersionUID = -7519241415237227977L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "ID") + private Customer customerId; + + @NotNull + @Column(name = "REFERENCE_NO", length = 75) + private String referenceNumber; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "orderId") + private List sampleJobs; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the customerId + */ + public Customer getCustomerId() { + return customerId; + } + + /** + * @param customerId the customerId to set + */ + public void setCustomerId(Customer customerId) { + this.customerId = customerId; + } + + /** + * @return the referenceNumber + */ + public String getReferenceNumber() { + return referenceNumber; + } + + /** + * @param referenceNumber the referenceNumber to set + */ + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } + + /** + * @return the sampleJobs + */ + public List getSampleJobs() { + return sampleJobs; + } + + /** + * @param sampleJobs the sampleJobs to set + */ + public void setSampleJobs(List sampleJobs) { + this.sampleJobs = sampleJobs; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/PantoneColor.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/PantoneColor.java new file mode 100644 index 0000000..6240455 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/PantoneColor.java @@ -0,0 +1,142 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; +import org.hibernate.annotations.Type; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllPantoneColors", query = "from PantoneColor p"), + @NamedQuery(name = "getPantoneColorById", query = "from PantoneColor p where p.id = :id")}) +@Entity +@Table(name = "PantoneColor", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"})}) +public class PantoneColor implements Serializable { + + private static final long serialVersionUID = -9051039421864097178L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @NotNull + @Column(name = "NAME", length = 100) + private String name; + + @NotNull + @Column(name = "CODE", length = 45) + private String code; + + @Type(type = "text") + @Column(name = "DESCRIPTION") + private String description; + + @NotNull + @Column(name = "HEX_CODE", length = 7) + private String hexCode; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pantoneColorId") + private List parts; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the code + */ + public String getCode() { + return code; + } + + /** + * @param code the code to set + */ + public void setCode(String code) { + this.code = code; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the hexCode + */ + public String getHexCode() { + return hexCode; + } + + /** + * @param hexCode the hexCode to set + */ + public void setHexCode(String hexCode) { + this.hexCode = hexCode; + } + + /** + * @return the parts + */ + public List getPart() { + return parts; + } + + /** + * @param parts the parts to set + */ + public void setPart(List parts) { + this.parts = parts; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Part.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Part.java new file mode 100644 index 0000000..a5543de --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Part.java @@ -0,0 +1,201 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; +import org.hibernate.annotations.Type; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllParts", query = "from Part p"), + @NamedQuery(name = "getPartById", query = "from Part p where p.id = :id")}) +@Entity +@Table(name = "Part", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"})}) +public class Part implements Serializable { + + private static final long serialVersionUID = -7854681959193849256L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "JOB_ID", referencedColumnName = "ID") + private SampleJob jobId; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "PANTONECOLOR_ID", referencedColumnName = "ID") + private PantoneColor pantoneColorId; + + @NotNull + @Column(name = "PART_NAME", length = 100) + private String partName; + + @Type(type = "text") + @Column(name = "DESCRIPTION") + private String description; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the jobId + */ + public SampleJob getJobId() { + return jobId; + } + + /** + * @param jobId the jobId to set + */ + public void setJobId(SampleJob jobId) { + this.jobId = jobId; + } + + /** + * @return the pantoneColorId + */ + public PantoneColor getPantoneColorId() { + return pantoneColorId; + } + + /** + * @param pantoneColorId the pantoneColorId to set + */ + public void setPantoneColorId(PantoneColor pantoneColorId) { + this.pantoneColorId = pantoneColorId; + } + + /** + * @return the partName + */ + public String getPartName() { + return partName; + } + + /** + * @param partName the partName to set + */ + public void setPartName(String partName) { + this.partName = partName; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Sample.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Sample.java new file mode 100644 index 0000000..48a806c --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Sample.java @@ -0,0 +1,217 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllSamples", query = "from Sample s"), + @NamedQuery(name = "getSampleById", query = "from Sample s where s.id = :id")}) +@Entity +@Table(name = "Sample", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"}), + @UniqueConstraint(columnNames = {"REFERENCE_NO"})}) +public class Sample implements Serializable { + + private static final long serialVersionUID = -6611672258755811793L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "JOB_ID", referencedColumnName = "ID") + private SampleJob jobId; + + @NotNull + @Column(name = "REFERENCE_NO", length = 75) + private String referenceNumber; + + @Column(name = "QUANTITY") + private int quantity; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + @Column(name = "QC_USER", length = 30) + private String qcUser; + + @Temporal(TemporalType.DATE) + @Column(name = "QC_DATETIME") + private Date qcDateTime; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the jobId + */ + public SampleJob getJobId() { + return jobId; + } + + /** + * @param jobId the jobId to set + */ + public void setJobId(SampleJob jobId) { + this.jobId = jobId; + } + + /** + * @return the referenceNumber + */ + public String getReferenceNumber() { + return referenceNumber; + } + + /** + * @param referenceNumber the referenceNumber to set + */ + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + /** + * @return the quantity + */ + public int getQuantity() { + return quantity; + } + + /** + * @param quantity the quantity to set + */ + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } + + /** + * @return the qcUser + */ + public String getQcUser() { + return qcUser; + } + + /** + * @param qcUser the qcUser to set + */ + public void setQcUser(String qcUser) { + this.qcUser = qcUser; + } + + /** + * @return the qcDateTime + */ + public Date getQcDateTime() { + return qcDateTime; + } + + /** + * @param qcDateTime the qcDateTime to set + */ + public void setQcDateTime(Date qcDateTime) { + this.qcDateTime = qcDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/SampleJob.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/SampleJob.java new file mode 100644 index 0000000..9ec77ac --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/SampleJob.java @@ -0,0 +1,329 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllSampleJobs", query = "from SampleJob s"), + @NamedQuery(name = "getSampleJobById", query = "from SampleJob s where s.id = :id")}) +@Entity +@Table(name = "SampleJob", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"}), + @UniqueConstraint(columnNames = {"REFERENCE_NO"})}) +public class SampleJob implements Serializable { + + private static final long serialVersionUID = 7907650640081075587L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "ORDER_ID", referencedColumnName = "ID") + private JobOrder orderId; + + @NotNull + @Column(name = "TITLE", length = 100) + private String title; + + @NotNull + @Column(name = "REFERENCE_NO", length = 75) + private String referenceNumber; + + @Column(name = "PRIORITY") + private int priority; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "ACCEPTED_DATE") + private Date acceptedDate; + + @Temporal(TemporalType.DATE) + @Column(name = "END_DATE") + private Date endDate; + + @NotNull + @Column(name = "STATUS") + private char status; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDate; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "jobId") + private List screens; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "jobId") + private List artworks; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "jobId") + private List deliveryAddresses; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "jobId") + private List parts; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "jobId") + private List samples; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the orderId + */ + public JobOrder getOrderId() { + return orderId; + } + + /** + * @param orderId the orderId to set + */ + public void setOrderId(JobOrder orderId) { + this.orderId = orderId; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the referenceNumber + */ + public String getReferenceNumber() { + return referenceNumber; + } + + /** + * @param referenceNumber the referenceNumber to set + */ + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + /** + * @return the priority + */ + public int getPriority() { + return priority; + } + + /** + * @param priority the priority to set + */ + public void setPriority(int priority) { + this.priority = priority; + } + + /** + * @return the acceptedDate + */ + public Date getAcceptedDate() { + return acceptedDate; + } + + /** + * @param acceptedDate the acceptedDate to set + */ + public void setAcceptedDate(Date acceptedDate) { + this.acceptedDate = acceptedDate; + } + + /** + * @return the endDate + */ + public Date getEndDate() { + return endDate; + } + + /** + * @param endDate the endDate to set + */ + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + /** + * @return the status + */ + public char getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(char status) { + this.status = status; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDate + */ + public Date getCreateDate() { + return createDate; + } + + /** + * @param createDate the createDate to set + */ + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } + + /** + * @return the screens + */ + public List getScreens() { + return screens; + } + + /** + * @param screens the screens to set + */ + public void setScreens(List screens) { + this.screens = screens; + } + + /** + * @return the artworks + */ + public List getArtworks() { + return artworks; + } + + /** + * @param artworks the artworks to set + */ + public void setArtworks(List artworks) { + this.artworks = artworks; + } + + /** + * @return the deliveryAddresses + */ + public List getDeliveryAddresses() { + return deliveryAddresses; + } + + /** + * @param deliveryAddresses the deliveryAddresses to set + */ + public void setDeliveryAddresses(List deliveryAddresses) { + this.deliveryAddresses = deliveryAddresses; + } + + /** + * @return the parts + */ + public List getParts() { + return parts; + } + + /** + * @param parts the parts to set + */ + public void setParts(List parts) { + this.parts = parts; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Screen.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Screen.java new file mode 100644 index 0000000..02869a8 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/Screen.java @@ -0,0 +1,146 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllScreens", query = "from Screen s"), + @NamedQuery(name = "getScreenById", query = "from Screen s where s.id = :id")}) +@Entity +@Table(name = "Screen", uniqueConstraints = { + @UniqueConstraint(columnNames = "ID")}) +public class Screen implements Serializable { + + private static final long serialVersionUID = -4415305021711461959L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "JOB_ID", referencedColumnName = "ID") + private SampleJob jobId; + + @NotNull + @Column(name = "CREATE_USER", length = 30) + private String createUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the jobId + */ + public SampleJob getJobId() { + return jobId; + } + + /** + * @param jobId the jobId to set + */ + public void setJobId(SampleJob jobId) { + this.jobId = jobId; + } + + /** + * @return the createUser + */ + public String getCreateUser() { + return createUser; + } + + /** + * @param createUser the createUser to set + */ + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/entity/User.java b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/User.java new file mode 100644 index 0000000..b22da79 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/entity/User.java @@ -0,0 +1,341 @@ +package com.blackhat.entity; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; + +/** + * + * @author Sachith Dickwella + */ +@NamedQueries({ + @NamedQuery(name = "getAllUsers", query = "from User s"), + @NamedQuery(name = "getUserById", query = "from User s where s.id = :id"), + @NamedQuery(name = "getUserByUserName", query = "from User s where s.userName = :userName")}) +@Entity +@Table(name = "User", uniqueConstraints = { + @UniqueConstraint(columnNames = {"ID"}), + @UniqueConstraint(columnNames = {"USER_NAME"})}) +public class User implements Serializable { + + private static final long serialVersionUID = -4841286092998426213L; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "ID") + private int id; + + @NotNull + @OneToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "USER_NAME", referencedColumnName = "USER_NAME") + private Credential userName; + + @NotNull + @Column(name = "FIRST_NAME", length = 40) + private String firstName; + + @NotNull + @Column(name = "LAST_NAME", length = 40) + private String lastName; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "BIRTH_DATE") + private Date birthDate; + + @NotNull + @Column(name = "GENDER", length = 1) + private char gender; + + @Column(name = "HOME_PHONENO", length = 20) + private String homePhone; + + @NotNull + @Column(name = "MOBILE_PHONENO", length = 20) + private String mobilePhone; + + @Column(name = "EMAIL", length = 50) + private String email; + + @Column(name = "ADDRESS_LINE1", length = 40) + private String addressLine1; + + @Column(name = "ADDRESS_LINE2", length = 40) + private String addressLine2; + + @Column(name = "CITY_TOWN", length = 30) + private String cityTown; + + @Column(name = "STATE_PROVINCE", length = 50) + private String stateProvince; + + @Column(name = "ZIP_CODE", length = 10) + private String zipCode; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "CREATE_DATETIME") + private Date createDateTime; + + @NotNull + @Column(name = "LASTUPDATE_USER", length = 30) + private String lastUpdateUser; + + @NotNull + @Temporal(TemporalType.DATE) + @Column(name = "LASTUPDATE_DATETIME") + private Date lastUpdateDateTime; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the userName + */ + public Credential getUserName() { + return userName; + } + + /** + * @param userName the userName to set + */ + public void setUserName(Credential userName) { + this.userName = userName; + } + + /** + * @return the firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName the firstName to set + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return the lastName + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName the lastName to set + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return the birthDate + */ + public Date getBirthDate() { + return birthDate; + } + + /** + * @param birthDate the birthDate to set + */ + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; + } + + /** + * @return the gender + */ + public char getGender() { + return gender; + } + + /** + * @param gender the gender to set + */ + public void setGender(char gender) { + this.gender = gender; + } + + /** + * @return the homePhone + */ + public String getHomePhone() { + return homePhone; + } + + /** + * @param homePhone the homePhone to set + */ + public void setHomePhone(String homePhone) { + this.homePhone = homePhone; + } + + /** + * @return the mobilePhone + */ + public String getMobilePhone() { + return mobilePhone; + } + + /** + * @param mobilePhone the mobilePhone to set + */ + public void setMobilePhone(String mobilePhone) { + this.mobilePhone = mobilePhone; + } + + /** + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * @param email the email to set + */ + public void setEmail(String email) { + this.email = email; + } + + /** + * @return the addressLine1 + */ + public String getAddressLine1() { + return addressLine1; + } + + /** + * @param addressLine1 the addressLine1 to set + */ + public void setAddressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + } + + /** + * @return the addressLine2 + */ + public String getAddressLine2() { + return addressLine2; + } + + /** + * @param addressLine2 the addressLine2 to set + */ + public void setAddressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + } + + /** + * @return the cityTown + */ + public String getCityTown() { + return cityTown; + } + + /** + * @param cityTown the cityTown to set + */ + public void setCityTown(String cityTown) { + this.cityTown = cityTown; + } + + /** + * @return the stateProvince + */ + public String getStateProvince() { + return stateProvince; + } + + /** + * @param stateProvince the stateProvince to set + */ + public void setStateProvince(String stateProvince) { + this.stateProvince = stateProvince; + } + + /** + * @return the zipCode + */ + public String getZipCode() { + return zipCode; + } + + /** + * @param zipCode the zipCode to set + */ + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + /** + * @return the createDateTime + */ + public Date getCreateDateTime() { + return createDateTime; + } + + /** + * @param createDateTime the createDateTime to set + */ + public void setCreateDateTime(Date createDateTime) { + this.createDateTime = createDateTime; + } + + /** + * @return the lastUpdateUser + */ + public String getLastUpdateUser() { + return lastUpdateUser; + } + + /** + * @param lastUpdateUser the lastUpdateUser to set + */ + public void setLastUpdateUser(String lastUpdateUser) { + this.lastUpdateUser = lastUpdateUser; + } + + /** + * @return the lastUpdateDateTime + */ + public Date getLastUpdateDateTime() { + return lastUpdateDateTime; + } + + /** + * @param lastUpdateDateTime the lastUpdateDateTime to set + */ + public void setLastUpdateDateTime(Date lastUpdateDateTime) { + this.lastUpdateDateTime = lastUpdateDateTime; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/factory/FactoryFacade.java b/sachith_task/RESTSource/src/main/java/com/blackhat/factory/FactoryFacade.java new file mode 100644 index 0000000..6183aa1 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/factory/FactoryFacade.java @@ -0,0 +1,30 @@ +package com.blackhat.factory; + +import java.util.List; + +/** + * @param + * @author Sachith Dickwella + */ +public abstract class FactoryFacade { + + public abstract int create(T type); + + public abstract List getAll(); + + public T getById(int id) { + return null; + } + + public T getByUserName(String userName) { + return null; + } + + public List getByName(String name) { + return null; + } + + public abstract int update(T type); + + public abstract int delete(int id); +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/listener/ContextListener.java b/sachith_task/RESTSource/src/main/java/com/blackhat/listener/ContextListener.java new file mode 100644 index 0000000..4a6e899 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/listener/ContextListener.java @@ -0,0 +1,43 @@ +package com.blackhat.listener; + +import static com.blackhat.BlackhatConstants.SESSION_FACTORY; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; +import org.apache.log4j.PropertyConfigurator; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.service.ServiceRegistry; + +/** + * + * @author Sachith Dickwella + */ +@WebListener +public class ContextListener implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + /** + * Log4j property configuration. + */ + PropertyConfigurator.configure(getClass().getResource("/log/log4j.properties")); + /** + * Hibernate property configuration. + */ + Configuration config = new Configuration().configure("/hbm/hibernate.cfg.xml"); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build(); + SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry); + + sce.getServletContext().setAttribute(SESSION_FACTORY, sessionFactory); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + SessionFactory sessionFactory = (SessionFactory) sce.getServletContext().getAttribute(SESSION_FACTORY); + if (sessionFactory != null && !sessionFactory.isClosed()) { + sessionFactory.close(); + } + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/security/Encryption.java b/sachith_task/RESTSource/src/main/java/com/blackhat/security/Encryption.java new file mode 100644 index 0000000..d8b2dc3 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/security/Encryption.java @@ -0,0 +1,52 @@ +package com.blackhat.security; + +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * + * @author Sachith Dickwela + */ +public class Encryption { + + public static enum Algorithm { + SHA_1, SHA_2, SHA_256, SHA_512, MD5 + } + + public static String encrypt(Algorithm method, String phrase) + throws NoSuchAlgorithmException { + String algorithm; + switch (method) { + case SHA_1: + algorithm = "SHA-1"; + break; + case SHA_2: + algorithm = "SHA-2"; + break; + case SHA_256: + algorithm = "SHA-256"; + break; + case SHA_512: + algorithm = "SHA-512"; + break; + case MD5: + algorithm = "MD5"; + break; + default: + algorithm = "MD5"; + break; + } + MessageDigest digest = MessageDigest.getInstance(algorithm); + byte[] buffer = digest.digest(phrase.getBytes(Charset.forName("UTF-8"))); + return toHexaString(buffer); + } + + private static String toHexaString(byte[] buffer) { + StringBuilder builder = new StringBuilder(); + for (byte bit : buffer) { + builder.append(String.format("%x", bit)); + } + return builder.toString(); + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/Resource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/Resource.java new file mode 100644 index 0000000..c50222b --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/Resource.java @@ -0,0 +1,75 @@ +package com.blackhat.service; + +import com.blackhat.service.subresource.ArtworkResource; +import com.blackhat.service.subresource.CustomerResource; +import com.blackhat.service.subresource.DeliveryAddressResource; +import com.blackhat.service.subresource.JobOrderResource; +import com.blackhat.service.subresource.PantoneColorResource; +import com.blackhat.service.subresource.PartResource; +import com.blackhat.service.subresource.SampleJobResource; +import com.blackhat.service.subresource.ScreenResource; +import com.blackhat.service.subresource.UserResource; +import javax.servlet.ServletContext; +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; + +/** + * + * @author Sachith Dickwella + */ +@Path("/resource") +public class Resource { + + @Context + private ServletContext context; + + @Path("/users") + public UserResource getUsers() { + return new UserResource(context); + } + + @Path("/customers") + public CustomerResource getCustomers() { + return new CustomerResource(context); + } + + @Path("/joborders") + public JobOrderResource getJobOrders() { + return new JobOrderResource(context); + } + + @Path("/samplejobs") + public SampleJobResource getSampleJobs() { + return new SampleJobResource(context); + } + + @Path("/pantonecolors") + public PantoneColorResource getPantoneColors() { + return new PantoneColorResource(context); + } + + @Path("/parts") + public PartResource getParts() { + return new PartResource(context); + } + + @Path("/screens") + public ScreenResource getScreens() { + return new ScreenResource(context); + } + + @Path("/artworks") + public ArtworkResource getArtworks() { + return new ArtworkResource(context); + } + + @Path("/deliveryaddresses") + public DeliveryAddressResource getDeliveryAddresses() { + return new DeliveryAddressResource(context); + } + + @Path("/samples") + public SampleJobResource getSamples() { + return new SampleJobResource(context); + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/ArtworkResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/ArtworkResource.java new file mode 100644 index 0000000..74da06a --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/ArtworkResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.Artwork; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class ArtworkResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(ArtworkResource.class); + + public ArtworkResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(Artwork type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllArtworks"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public Artwork getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getArtworkById"); + query.setInteger("id", id); + List artworks = query.list(); + if (artworks.size() > 0) { + return artworks.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(Artwork type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/CustomerResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/CustomerResource.java new file mode 100644 index 0000000..ca28674 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/CustomerResource.java @@ -0,0 +1,155 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.Customer; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class CustomerResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(CustomerResource.class); + + public CustomerResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(Customer type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllCustomers"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public Customer getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getCustomerById"); + query.setInteger("id", id); + List customers = query.list(); + if (customers.size() > 0) { + return customers.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/customer/{name}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getByName(@PathParam(value = "name") String name) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getCustomerByName"); + query.setString("name", name); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("aplication/json") + @Override + public int update(Customer type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/DeliveryAddressResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/DeliveryAddressResource.java new file mode 100644 index 0000000..7f1919f --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/DeliveryAddressResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.DeliveryAddress; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class DeliveryAddressResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(DeliveryAddressResource.class); + + public DeliveryAddressResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(DeliveryAddress type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllDeliveryAddresses"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public DeliveryAddress getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getDeliveryAddressById"); + query.setInteger("id", id); + List deliveryAddresses = query.list(); + if (deliveryAddresses.size() > 0) { + return deliveryAddresses.get(0); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(DeliveryAddress type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/JobOrderResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/JobOrderResource.java new file mode 100644 index 0000000..733f44a --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/JobOrderResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.JobOrder; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sahith Dickwella + */ +public class JobOrderResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(JobOrderResource.class); + + public JobOrderResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(JobOrder type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllJobOrders"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public JobOrder getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getJobOrderById"); + query.setInteger("id", id); + List jobOrders = query.list(); + if (jobOrders.size() > 0) { + return jobOrders.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(JobOrder type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/PantoneColorResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/PantoneColorResource.java new file mode 100644 index 0000000..1f45128 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/PantoneColorResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.PantoneColor; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class PantoneColorResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(PantoneColorResource.class); + + public PantoneColorResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(PantoneColor type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllPantoneColors"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public PantoneColor getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getPantoneColorById"); + query.setInteger("id", id); + List pantoneColors = query.list(); + if (pantoneColors.size() > 0) { + return pantoneColors.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(PantoneColor type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/PartResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/PartResource.java new file mode 100644 index 0000000..8f93e51 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/PartResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.Part; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class PartResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(PartResource.class); + + public PartResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(Part type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllParts"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public Part getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getPartById"); + query.setInteger("id", id); + List parts = query.list(); + if (parts.size() > 0) { + return parts.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(Part type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/SampleJobResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/SampleJobResource.java new file mode 100644 index 0000000..45a1689 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/SampleJobResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.SampleJob; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class SampleJobResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(SampleJobResource.class); + + public SampleJobResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(SampleJob type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllSampleJobs"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public SampleJob getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getSampleJobById"); + query.setInteger("id", id); + List sampleJobs = query.list(); + if (sampleJobs.size() > 0) { + return sampleJobs.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(SampleJob type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/SampleResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/SampleResource.java new file mode 100644 index 0000000..8f8f765 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/SampleResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.Sample; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class SampleResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(SampleResource.class); + + public SampleResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(Sample type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllSamples"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public Sample getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getSampleById"); + query.setInteger("id", id); + List samples = query.list(); + if (samples.size() > 0) { + return samples.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(Sample type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/ScreenResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/ScreenResource.java new file mode 100644 index 0000000..53b2244 --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/ScreenResource.java @@ -0,0 +1,137 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.Screen; +import com.blackhat.factory.FactoryFacade; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class ScreenResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(ScreenResource.class); + + public ScreenResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(Screen type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllScreens"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public Screen getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getScreenById"); + query.setInteger("id", id); + List screens = query.list(); + if (screens.size() > 0) { + return screens.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(Screen type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/UserResource.java b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/UserResource.java new file mode 100644 index 0000000..3c0bf4b --- /dev/null +++ b/sachith_task/RESTSource/src/main/java/com/blackhat/service/subresource/UserResource.java @@ -0,0 +1,158 @@ +package com.blackhat.service.subresource; + +import static com.blackhat.BlackhatConstants.getSession; +import com.blackhat.entity.User; +import com.blackhat.factory.FactoryFacade; +import com.blackhat.security.Encryption; +import java.util.Arrays; +import java.util.List; +import javax.servlet.ServletContext; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * + * @author Sachith Dickwella + */ +public class UserResource extends FactoryFacade { + + private final ServletContext context; + private final Logger logger = Logger.getLogger(UserResource.class); + + public UserResource(ServletContext context) { + this.context = context; + } + + @PUT + @Path("/") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int create(User type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + int genId = 0; + try { + type.getUserName().setPassword(Encryption.encrypt(Encryption.Algorithm.SHA_256, type.getUserName().getPassword())); + genId = (Integer) session.save(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + genId = -1; + } finally { + session.close(); + } + return genId; + } + + @GET + @Path("/") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public List getAll() { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getAllUsers"); + return query.list(); + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/{id}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public User getById(@PathParam(value = "id") int id) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getUserById").setInteger("id", id); + List users = query.list(); + if (users.size() > 0) { + return users.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @GET + @Path("/user/{userName}") + @Produces({"application/xml; qs=0.9", "application/json"}) + @Override + public User getByUserName(@PathParam(value = "userName") String userName) { + Session session = getSession(context); + try { + Query query = session.getNamedQuery("getUserByUserName").setString("userName", userName); + List users = query.list(); + if (users.size() > 0) { + return users.get(1); + } + } catch (Exception e) { + logger.error(Arrays.toString(e.getStackTrace())); + } finally { + session.close(); + } + return null; + } + + @POST + @Path("/update") + @Produces("text/plain") + @Consumes("application/json") + @Override + public int update(User type) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + session.update(type); + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } + + @DELETE + @Path("/delete/{id}") + @Produces("text/plain") + @Override + public int delete(@PathParam(value = "id") int id) { + Session session = getSession(context); + Transaction tx = session.beginTransaction(); + try { + /** + * TODO code here + */ + tx.commit(); + } catch (Exception e) { + tx.rollback(); + logger.error(Arrays.toString(e.getStackTrace())); + return -1; + } finally { + session.close(); + } + return 0; + } +} diff --git a/sachith_task/RESTSource/src/main/resources/hbm/hibernate.cfg.xml b/sachith_task/RESTSource/src/main/resources/hbm/hibernate.cfg.xml new file mode 100644 index 0000000..16da3f0 --- /dev/null +++ b/sachith_task/RESTSource/src/main/resources/hbm/hibernate.cfg.xml @@ -0,0 +1,21 @@ + + + + + jdbc/__ERPMySQLPool + org.hibernate.dialect.MySQLDialect + validate + + + + + + + + + + + + + + diff --git a/sachith_task/RESTSource/src/main/resources/log/log4j.properties b/sachith_task/RESTSource/src/main/resources/log/log4j.properties new file mode 100644 index 0000000..8c753c2 --- /dev/null +++ b/sachith_task/RESTSource/src/main/resources/log/log4j.properties @@ -0,0 +1,14 @@ +# Logging path +logpath=/var/log/blackhat + +# Define the root logger with appender file +log4j.rootLogger = ERROR, FILE + +# Define the file appender +log4j.appender.FILE=org.apache.log4j.RollingFileAppender +log4j.appender.FILE.File=${logpath}/error-log.log +log4j.appender.FILE.MaxFileSize=100MB + +# Define the layout for file appender +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.conversionPattern=ERROR: %l at %d{dd-MMM-yyyy HH:mm:ss} - %m%n \ No newline at end of file diff --git a/sachith_task/RESTSource/src/main/webapp/WEB-INF/glassfish-web.xml b/sachith_task/RESTSource/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..bb1fc17 --- /dev/null +++ b/sachith_task/RESTSource/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,11 @@ + + + + /blackhat + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/sachith_task/RESTSource/src/main/webapp/WEB-INF/web.xml b/sachith_task/RESTSource/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..3021aca --- /dev/null +++ b/sachith_task/RESTSource/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,27 @@ + + + + REST_APISupportServiceServlets + org.glassfish.jersey.servlet.ServletContainer + + jersey.config.server.provider.packages + com.blackhat.service + + + jersey.config.server.provider.scanning.recursive + true + + + + REST_APISupportServiceServlets + /rest/* + + + + 30 + + + diff --git a/sachith_task/Showcase/.gitignore b/sachith_task/Showcase/.gitignore new file mode 100644 index 0000000..c6cbe56 --- /dev/null +++ b/sachith_task/Showcase/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/sachith_task/Showcase/.idea/.name b/sachith_task/Showcase/.idea/.name new file mode 100644 index 0000000..bd89266 --- /dev/null +++ b/sachith_task/Showcase/.idea/.name @@ -0,0 +1 @@ +Showcase \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/compiler.xml b/sachith_task/Showcase/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/sachith_task/Showcase/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/copyright/profiles_settings.xml b/sachith_task/Showcase/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/sachith_task/Showcase/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/dictionaries/Dilki_Nisansala.xml b/sachith_task/Showcase/.idea/dictionaries/Dilki_Nisansala.xml new file mode 100644 index 0000000..79899e8 --- /dev/null +++ b/sachith_task/Showcase/.idea/dictionaries/Dilki_Nisansala.xml @@ -0,0 +1,8 @@ + + + + glassfish + larg + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/encodings.xml b/sachith_task/Showcase/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/sachith_task/Showcase/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/gradle.xml b/sachith_task/Showcase/.idea/gradle.xml new file mode 100644 index 0000000..fc132b2 --- /dev/null +++ b/sachith_task/Showcase/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/inspectionProfiles/Project_Default.xml b/sachith_task/Showcase/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..a590ed7 --- /dev/null +++ b/sachith_task/Showcase/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/inspectionProfiles/profiles_settings.xml b/sachith_task/Showcase/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/sachith_task/Showcase/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/misc.xml b/sachith_task/Showcase/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/sachith_task/Showcase/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/modules.xml b/sachith_task/Showcase/.idea/modules.xml new file mode 100644 index 0000000..913b45a --- /dev/null +++ b/sachith_task/Showcase/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/runConfigurations.xml b/sachith_task/Showcase/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/sachith_task/Showcase/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/.idea/vcs.xml b/sachith_task/Showcase/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/sachith_task/Showcase/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/app/.gitignore b/sachith_task/Showcase/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/sachith_task/Showcase/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/sachith_task/Showcase/app/build.gradle b/sachith_task/Showcase/app/build.gradle new file mode 100644 index 0000000..c4942e7 --- /dev/null +++ b/sachith_task/Showcase/app/build.gradle @@ -0,0 +1,41 @@ +apply plugin: 'com.android.application' + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:design:23.1.1' + /** Jersey REST Client dependencies*/ + compile('org.glassfish.jersey.core:jersey-client:2.22.1') { + exclude group: 'javax.inject', module: 'javax.inject' + } + compile 'javax.activation:activation:1.1.1' + compile 'com.android.support:design:23.1.0' +} + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "com.mi.showcase" + minSdkVersion 19 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + multiDexEnabled true + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + packagingOptions { + exclude 'META-INF/LICENSE.txt' + } +} diff --git a/sachith_task/Showcase/app/proguard-rules.pro b/sachith_task/Showcase/app/proguard-rules.pro new file mode 100644 index 0000000..8a2f402 --- /dev/null +++ b/sachith_task/Showcase/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/sachith_task/Showcase/app/src/main/AndroidManifest.xml b/sachith_task/Showcase/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..88df3b8 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/InsertDataActivity.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/InsertDataActivity.java new file mode 100644 index 0000000..f695caf --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/InsertDataActivity.java @@ -0,0 +1,121 @@ +package com.mi.showcase; + +import android.content.Context; +import android.os.Bundle; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.ProgressBar; +import android.widget.ScrollView; +import android.widget.TextView; + +import com.mi.showcase.exec.ShowcaseMobileTask; +import com.mi.showcase.util.DialogTypes; +import com.mi.showcase.util.MessageHandler; +import com.mi.showcase.util.ShowcaseUtils; +import com.mi.showcase.view.dto.MobileDataListModel; + +public class InsertDataActivity extends AppCompatActivity { + + private TextView[] textViews = new TextView[9]; + + private ProgressBar savingProgressBar; + private ScrollView scrollView; + private ShowcaseUtils.ShowcaseUtilDialogs connectionDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_insert_data); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + connectionDialog = new ShowcaseUtils.ShowcaseUtilDialogs(this, DialogTypes.CONNECTION_DIALOG, null, null); + + textViews[0] = (TextView) findViewById(R.id.deviceName); + textViews[1] = (TextView) findViewById(R.id.androidName); + textViews[2] = (TextView) findViewById(R.id.carrier); + textViews[3] = (TextView) findViewById(R.id.version); + textViews[4] = (TextView) findViewById(R.id.target); + textViews[5] = (TextView) findViewById(R.id.codeName); + textViews[6] = (TextView) findViewById(R.id.distribution); + textViews[7] = (TextView) findViewById(R.id.remark); + textViews[8] = (TextView) findViewById(R.id.imageUrl); + + savingProgressBar = (ProgressBar) findViewById(R.id.savingProgress); + scrollView = (ScrollView) findViewById(R.id.savingScroller); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_insert_data, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_save: + boolean isConnected = ShowcaseUtils.isConnected(getApplicationContext()); + if (!isConnected) { + connectionDialog.showDialog(null); + } else { + boolean isRequiredEmpty = false; + for (TextView textView : textViews) { + if (!textView.equals(textViews[2])) { + if (!textView.equals(textViews[8])) { + String text = textView.getText().toString(); + if (text.equals(getString(R.string.empty_string))) { + isRequiredEmpty = true; + } + } + } + } + if (!isRequiredEmpty) { + try { + View view = this.getCurrentFocus(); + if (view != null) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + MessageHandler.executeHandler(saveData); + } catch (InterruptedException ex) { + Log.e(ex.getMessage(), ex.toString()); + } + } else { + Snackbar.make(scrollView, getString(R.string.required_fields_empty), Snackbar.LENGTH_LONG).show(); + } + } + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private final Runnable saveData = new Runnable() { + @Override + public void run() { + MobileDataListModel mobileDataListModel = new MobileDataListModel(); + mobileDataListModel.setDeviceName(textViews[0].getText().toString()); + mobileDataListModel.setAndroidName(textViews[1].getText().toString()); + mobileDataListModel.setCarrier(textViews[2].getText().toString()); + mobileDataListModel.setVersion(textViews[3].getText().toString()); + mobileDataListModel.setTarget(textViews[4].getText().toString()); + mobileDataListModel.setCodeName(textViews[5].getText().toString()); + mobileDataListModel.setDistribution(textViews[6].getText().toString()); + mobileDataListModel.setSnippet(textViews[7].getText().toString()); + mobileDataListModel.setImageUrl(textViews[8].getText().toString()); + + ShowcaseMobileTask.AddDeviceTask addDeviceTask + = new ShowcaseMobileTask.AddDeviceTask(InsertDataActivity.this, savingProgressBar, scrollView, textViews); + addDeviceTask.execute(mobileDataListModel); + } + }; +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/ShowCaseActivity.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/ShowCaseActivity.java new file mode 100644 index 0000000..179b575 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/ShowCaseActivity.java @@ -0,0 +1,173 @@ +package com.mi.showcase; + +import android.content.Intent; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.Process; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; + +import com.mi.showcase.exec.ShowcaseMobileTask; +import com.mi.showcase.util.DialogTypes; +import com.mi.showcase.util.MessageHandler; +import com.mi.showcase.util.ShowcaseUtils; +import com.mi.showcase.view.MobileDataAdapter; +import com.mi.showcase.view.dto.MobileDataListModel; + +import org.json.JSONObject; + +import java.io.BufferedInputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ExecutionException; + +/** + * @author Sachith Dickwella + */ +public class ShowCaseActivity extends AppCompatActivity { + + private static SwipeRefreshLayout swipToRefreshLayout; + private ShowcaseUtils.ShowcaseUtilDialogs connectionDialog; + private ShowcaseUtils.ShowcaseUtilDialogs informationDialog; + private static ListView dataListView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_show_case); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar.setSubtitle(R.string.app_subtitle); + setSupportActionBar(toolbar); + + dataListView = (ListView) findViewById(R.id.dataList); + + connectionDialog = new ShowcaseUtils.ShowcaseUtilDialogs(this, DialogTypes.CONNECTION_DIALOG, new ShowcaseUtils.ShowcaseUtilDialogs.InterceptionBeforeExecutor() { + @Override + public void run() { + swipToRefreshLayout.setRefreshing(false); + } + }, null); + informationDialog = new ShowcaseUtils.ShowcaseUtilDialogs(this, DialogTypes.INFORMATION_DIALOG, null, null); + + swipToRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); + swipToRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + boolean isConnected = ShowcaseUtils.isConnected(getApplicationContext()); + if (!isConnected) { + connectionDialog.showDialog(null); + } else { + try { + MessageHandler.executeHandler(loadData); + } catch (InterruptedException ex) { + Log.e(ex.getMessage(), ex.toString()); + } + } + } + }); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent insertDataIntent = new Intent(ShowCaseActivity.this, InsertDataActivity.class); + startActivity(insertDataIntent); + } + }); + + dataListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + boolean isConnected = ShowcaseUtils.isConnected(getApplicationContext()); + if (!isConnected) { + connectionDialog.showDialog(null); + } else { + MobileDataListModel mobileDataListModel = ((MobileDataAdapter) parent.getAdapter()).getItem(position); + informationDialog.showDialog(mobileDataListModel); + } + } + }); + + List mobileDataListModels = new LinkedList<>(); + try (BufferedInputStream fin = new BufferedInputStream(openFileInput(getString(R.string.data_store)))) { + byte[] buffer = new byte[fin.available()]; + fin.read(buffer); + + JSONObject jsonObject = new JSONObject(new String(buffer)); + ShowcaseMobileTask.MobileDataLoadTask mobileDataLoadTask + = new ShowcaseMobileTask.MobileDataLoadTask(this, null); + mobileDataLoadTask.selectJSON(mobileDataListModels, + jsonObject.getJSONArray(getString(R.string.android)), + jsonObject.getJSONArray(getString(R.string.devices))); + + } catch (Exception ex) { + Log.e(ex.getMessage(), ex.toString()); + } finally { + System.gc(); + } + MobileDataAdapter mobileDataAdapter = new MobileDataAdapter(this, mobileDataListModels); + dataListView.setAdapter(mobileDataAdapter); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_showcase, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_refresh: + boolean isConnected = ShowcaseUtils.isConnected(getApplicationContext()); + if (!isConnected) { + connectionDialog.showDialog(null); + } else { + try { + MessageHandler.executeHandler(loadData); + } catch (InterruptedException ex) { + Log.e(ex.getMessage(), ex.toString()); + } + } + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private final Runnable loadData = new Runnable() { + @Override + public void run() { + ShowcaseMobileTask.MobileDataLoadTask dataLoadTask + = new ShowcaseMobileTask.MobileDataLoadTask(ShowCaseActivity.this, swipToRefreshLayout); + AsyncTask> asyncTask = dataLoadTask.execute((Void) null); + try { + @SuppressWarnings("unchecked") + List mobileData = (List) asyncTask.get(); + final MobileDataAdapter mobileDataAdapter = new MobileDataAdapter(ShowCaseActivity.this, mobileData); + + MessageHandler.sendMessageHandler(new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + dataListView.setAdapter(mobileDataAdapter); + } + }, null, null); + } catch (InterruptedException | ExecutionException e) { + Log.e(e.getMessage(), e.toString()); + } + } + }; +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/dialog/ConnectionDialog.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/dialog/ConnectionDialog.java new file mode 100644 index 0000000..df90f6d --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/dialog/ConnectionDialog.java @@ -0,0 +1,37 @@ +package com.mi.showcase.dialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.provider.Settings; + +import com.mi.showcase.R; + +/** + * @author Sachith Dickwella + */ +public class ConnectionDialog extends DialogFragment { + + public Dialog onCreateDialog(final Bundle savedInstance) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) + .setTitle(R.string.title_connection_dialog) + .setMessage(R.string.message_connection_dialog) + .setPositiveButton(R.string.dialog_settins, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS); + startActivity(settingsIntent, savedInstance); + } + }).setNegativeButton(R.string.dialog_cancle, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + return builder.create(); + } +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/dialog/InformationDialog.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/dialog/InformationDialog.java new file mode 100644 index 0000000..ee48a01 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/dialog/InformationDialog.java @@ -0,0 +1,96 @@ +package com.mi.showcase.dialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.mi.showcase.R; +import com.mi.showcase.exec.ShowcaseMobileTask; +import com.mi.showcase.util.MessageHandler; +import com.mi.showcase.view.dto.MobileDataListModel; + +/** + * @author Sachith Dickwella + */ +public class InformationDialog extends DialogFragment { + + private ImageView imageView; + private ProgressBar progressBar; + private View view; + + private MobileDataListModel mobileDataListModel; + private Thread isolatedThread; + + public void setMobileDataListModel(MobileDataListModel mobileDataListModel) { + this.mobileDataListModel = mobileDataListModel; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstances) { + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()) + .setTitle(R.string.title_information_dialog); + LayoutInflater inflater = getActivity().getLayoutInflater(); + view = inflater.inflate(R.layout.dialog_information, null); + alertDialogBuilder.setView(view) + .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + + return alertDialogBuilder.create(); + } + + @Override + public void onStart() { + super.onStart(); + imageView = (ImageView) view.findViewById(R.id.mobilePhoneImage); + progressBar = (ProgressBar) view.findViewById(R.id.progressBar); + TextView deviceName = (TextView) view.findViewById(R.id.deviceName); + TextView androidName = (TextView) view.findViewById(R.id.androidName); + TextView codeName = (TextView) view.findViewById(R.id.codeName); + TextView distribution = (TextView) view.findViewById(R.id.distribution); + TextView carrier = (TextView) view.findViewById(R.id.carrier); + TextView snippet = (TextView) view.findViewById(R.id.snippet); + TextView version = (TextView) view.findViewById(R.id.version); + + deviceName.setText(mobileDataListModel.getDeviceName()); + androidName.setText(mobileDataListModel.getAndroidName()); + codeName.setText(getString(R.string.code_name) + mobileDataListModel.getCodeName()); + distribution.setText(getString(R.string.distribution) + mobileDataListModel.getDistribution()); + version.setText(getString(R.string.version) + mobileDataListModel.getVersion()); + carrier.setText(getString(R.string.carrier) + mobileDataListModel.getCarrier()); + snippet.setText(mobileDataListModel.getSnippet()); + + try { + isolatedThread = MessageHandler.executeHandler(loadImage); + } catch (InterruptedException ex) { + Log.e(ex.getMessage(), ex.toString()); + } + } + + @Override + public void onStop() { + super.onStop(); + if (isolatedThread.isAlive()) { + isolatedThread.interrupt(); + } + } + + private final Runnable loadImage = new Runnable() { + @Override + public void run() { + ShowcaseMobileTask.LoadImageTask loadImageTask = new ShowcaseMobileTask.LoadImageTask(getActivity(), imageView, progressBar); + loadImageTask.execute(mobileDataListModel.getImageUrl()); + } + }; +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/exec/ShowcaseMobileTask.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/exec/ShowcaseMobileTask.java new file mode 100644 index 0000000..3ead641 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/exec/ShowcaseMobileTask.java @@ -0,0 +1,388 @@ +package com.mi.showcase.exec; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.support.design.widget.Snackbar; +import android.support.v4.graphics.drawable.RoundedBitmapDrawable; +import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.ScrollView; +import android.widget.TextView; + +import com.mi.showcase.R; +import com.mi.showcase.util.AndroidFriendlyFeatures; +import com.mi.showcase.util.MessageHandler; +import com.mi.showcase.view.dto.MobileDataListModel; + +import org.glassfish.jersey.client.ClientConfig; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedOutputStream; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * @author Sachith Dickwella + */ +public abstract class ShowcaseMobileTask extends AsyncTask { + + private final static String WEB_TARGET = "http://mobilesandboxdev.azurewebsites.net/"; + private final static String ANDROID_PATH = "android"; + private final static String DEVICES_PATH = "devices"; + + private Context context; + /** + * Only use in MobileDataLoadTask class + */ + private static SwipeRefreshLayout swipeRefreshLayout; + private static ImageView imageView; + private static ProgressBar progressBar; + private static ProgressBar progressBarSave; + private static ScrollView scrollView; + private static TextView[] textViews; + + public static class MobileDataLoadTask extends ShowcaseMobileTask> { + + public MobileDataLoadTask(Context context, SwipeRefreshLayout swipeRefreshLayout) { + ShowcaseMobileTask.swipeRefreshLayout = swipeRefreshLayout; + super.context = context; + } + + @Override + protected List doInBackground(Void... params) { + final Client client = ClientBuilder.newClient(new ClientConfig().register(new AndroidFriendlyFeatures())); + List mobileDataList = new LinkedList<>(); + try { + Callable androidCallable = new Callable() { + @Override + public String call() throws Exception { + return client.target(WEB_TARGET).path(ANDROID_PATH) + .request(MediaType.APPLICATION_JSON_TYPE).get(String.class); + } + }; + + Callable devicesCallable = new Callable() { + @Override + public String call() throws Exception { + return client.target(WEB_TARGET).path(DEVICES_PATH) + .request(MediaType.APPLICATION_JSON_TYPE).get(String.class); + } + }; + + ExecutorService executorService = Executors.newCachedThreadPool(); + Future androidFuture = executorService.submit(androidCallable); + Future devicesFuture = executorService.submit(devicesCallable); + + String json = "{ \"android\":" + androidFuture.get() + ", \"devices\":" + devicesFuture.get() + "}"; + + try (BufferedOutputStream fos = new BufferedOutputStream( + super.context.openFileOutput(super.context.getString(R.string.data_store), Context.MODE_PRIVATE))) { + fos.write(json.getBytes()); + fos.flush(); + } catch (Exception e) { + Log.e(e.getMessage(), e.toString()); + } + + JSONObject jsonObject = new JSONObject(json); + mobileDataList = selectJSON(mobileDataList, + jsonObject.getJSONArray(super.context.getString(R.string.android)), + jsonObject.getJSONArray(super.context.getString(R.string.devices))); + + } catch (Exception ex) { + Log.e(ex.getMessage(), ex.toString()); + Snackbar.make(swipeRefreshLayout, super.context.getResources() + .getText(R.string.service_unavailable), Snackbar.LENGTH_LONG).show(); + } finally { + client.close(); + System.gc(); + } + return mobileDataList; + } + + @Override + protected void onPreExecute() { + MessageHandler.sendMessageHandler(ShowcaseMobileTask.swipeRefreshingHandler, null, null); + } + + @Override + protected void onPostExecute(List list) { + swipeRefreshLayout.setRefreshing(false); + } + + public List selectJSON(List dataList, + JSONArray androidArray, JSONArray devicesArray) throws JSONException { + for (int i = 0; i < androidArray.length(); i++) { + JSONObject androidObject = (JSONObject) androidArray.get(i); + for (int x = 0; x < devicesArray.length(); x++) { + JSONObject devicesObject = (JSONObject) devicesArray.get(x); + try { + if (androidObject.getInt("id") == devicesObject.getInt("androidId")) { + MobileDataListModel listModel = new MobileDataListModel(); + + try { + listModel.setId(androidObject.getInt("id")); + listModel.setAndroidName(androidObject.getString("name")); + listModel.setVersion(androidObject.getString("version")); + listModel.setDeviceName(devicesObject.getString("name")); + listModel.setCodeName(androidObject.getString("codename")); + listModel.setDistribution(androidObject.getString("distribution")); + try { + listModel.setCarrier(devicesObject.getString("carrier")); + } catch (JSONException ex) { + listModel.setCarrier(super.context.getString(R.string.none)); + } + listModel.setSnippet(devicesObject.getString("snippet")); + listModel.setImageUrl(devicesObject.getString("imageUrl")); + } catch (JSONException ex) { + Log.e(ex.getMessage(), ex.toString()); + } + dataList.add(listModel); + } + } catch (JSONException ex) { + Log.e(ex.getMessage(), ex.toString()); + } + } + } + return dataList; + } + } + + /** + * Declare in outer class to avoid memory-leaks. + */ + @SuppressLint("HandlerLeak") + private static Handler swipeRefreshingHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + swipeRefreshLayout.setRefreshing(true); + } + }; + + public static class LoadImageTask extends ShowcaseMobileTask { + + public LoadImageTask(Context context, View... view) { + ShowcaseMobileTask.imageView = (ImageView) view[0]; + ShowcaseMobileTask.progressBar = (ProgressBar) view[1]; + super.context = context; + } + + @Override + protected Void doInBackground(String... params) { + try { + URL url = new URL(params[0]); + final Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream()); + final RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(super.context.getResources(), bmp); + roundedBitmapDrawable.setCornerRadius(Math.max(bmp.getWidth(), bmp.getHeight()) / 2.0f); + + @SuppressLint("HandlerLeak") final + Handler imageSetHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + imageView.setImageDrawable(roundedBitmapDrawable); + } + }; + + MessageHandler.sendMessageHandler(imageSetHandler, null, null); + } catch (Exception ex) { + Log.e(ex.getMessage(), ex.toString()); + } + return null; + } + + @Override + protected void onPreExecute() { + MessageHandler.sendMessageHandler(startLoadHandler, null, null); + } + + @Override + protected void onPostExecute(Void none) { + MessageHandler.sendMessageHandler(endLoadHandler, null, null); + } + } + + @SuppressLint("HandlerLeak") + private static Handler startLoadHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + progressBar.setVisibility(View.VISIBLE); + imageView.setVisibility(View.INVISIBLE); + } + }; + + @SuppressLint("HandlerLeak") + private static Handler endLoadHandler = new Handler(Looper.getMainLooper()) { + public void handleMessage(Message message) { + progressBar.setVisibility(View.INVISIBLE); + imageView.setVisibility(View.VISIBLE); + } + }; + + public static class AddDeviceTask extends ShowcaseMobileTask { + + public AddDeviceTask(Context context, Object... objs) { + super.context = context; + ShowcaseMobileTask.progressBarSave = (ProgressBar) objs[0]; + ShowcaseMobileTask.scrollView = (ScrollView) objs[1]; + ShowcaseMobileTask.textViews = (TextView[]) objs[2]; + } + + @Override + protected Void doInBackground(MobileDataListModel... params) { + final Client client = ClientBuilder.newClient(new ClientConfig().register(new AndroidFriendlyFeatures())); + try { + Callable androidCallable = new Callable() { + @Override + public String call() throws Exception { + return client.target(WEB_TARGET).path(ANDROID_PATH) + .request(MediaType.APPLICATION_JSON_TYPE).get(String.class); + } + }; + + Callable devicesCallable = new Callable() { + @Override + public String call() throws Exception { + return client.target(WEB_TARGET).path(DEVICES_PATH) + .request(MediaType.APPLICATION_JSON_TYPE).get(String.class); + } + }; + + ExecutorService executorService = Executors.newCachedThreadPool(); + Future androidFuture = executorService.submit(androidCallable); + Future devicesFuture = executorService.submit(devicesCallable); + + JSONArray androidArray = new JSONArray(androidFuture.get()); + JSONArray devicesArray = new JSONArray(devicesFuture.get()); + + int _MAX_androidId = 0, _MAX_devicesId = 0; + for (int i = 0; i < androidArray.length(); i++) { + JSONObject obj = androidArray.getJSONObject(i); + if (obj.getInt("id") > _MAX_androidId) { + _MAX_androidId = obj.getInt("id"); + } + } + for (int i = 0; i < devicesArray.length(); i++) { + JSONObject obj = devicesArray.getJSONObject(i); + if (obj.getInt("id") > _MAX_devicesId) { + _MAX_devicesId = obj.getInt("id"); + } + } + + MobileDataListModel mobileDataListModel = params[0]; + + final JSONObject androidObject = new JSONObject(); + androidObject.put("id", _MAX_androidId + 1) + .put("name", mobileDataListModel.getAndroidName()) + .put("version", mobileDataListModel.getVersion()) + .put("codename", mobileDataListModel.getCodeName()) + .put("target", mobileDataListModel.getTarget()) + .put("distribution", mobileDataListModel.getDistribution()); + + final JSONObject devicesObject = new JSONObject(); + devicesObject.put("id", _MAX_devicesId + 1) + .put("androidId", _MAX_androidId + 1) + .put("carrier", mobileDataListModel.getCarrier()) + .put("imageUrl", mobileDataListModel.getImageUrl()) + .put("name", mobileDataListModel.getDeviceName()) + .put("snippet", mobileDataListModel.getSnippet()); + + Callable androidSaveCall = new Callable() { + @Override + public Response call() throws Exception { + return client.target(WEB_TARGET).path(ANDROID_PATH) + .request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(androidObject.toString(), + MediaType.APPLICATION_JSON_TYPE)); + } + }; + + final Callable devicesSaveCall = new Callable() { + @Override + public Response call() throws Exception { + return client.target(WEB_TARGET).path(DEVICES_PATH) + .request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(devicesObject.toString(), MediaType.APPLICATION_JSON_TYPE)); + } + }; + + ExecutorService executorSaveService = Executors.newSingleThreadExecutor(); + Future androidFutureResponse = executorSaveService.submit(androidSaveCall); + Future devicesFutureResponse = executorSaveService.submit(devicesSaveCall); + + Response androidResponse = androidFutureResponse.get(); + Response devicesResponse = devicesFutureResponse.get(); + + if (androidResponse.getStatus() == 201 + && devicesResponse.getStatus() == 201) { + MessageHandler.sendMessageHandler(clearTextFields, null, null); + Snackbar.make(scrollView, super.context.getString(R.string.saving_process_succes), Snackbar.LENGTH_LONG).show(); + } else { + Snackbar.make(scrollView, super.context.getString(R.string.saving_process_failed), Snackbar.LENGTH_LONG).show(); + } + } catch (Exception ex) { + Log.e(ex.getMessage(), ex.toString()); + } finally { + client.close(); + } + return null; + } + + @Override + public void onPreExecute() { + MessageHandler.sendMessageHandler(saveStartHandler, null, null); + } + + @Override + public void onPostExecute(Void none) { + MessageHandler.sendMessageHandler(saveEndHandler, null, null); + } + } + + @SuppressLint("HandlerLeak") + private static Handler saveStartHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + scrollView.setVisibility(View.INVISIBLE); + progressBarSave.setVisibility(View.VISIBLE); + } + }; + + @SuppressLint("HandlerLeak") + private static Handler saveEndHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + scrollView.setVisibility(View.VISIBLE); + progressBarSave.setVisibility(View.INVISIBLE); + } + }; + + @SuppressLint("HandlerLeak") + private static Handler clearTextFields = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message message) { + for (TextView textView : textViews) { + textView.setText(""); + } + } + }; +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/AndroidFriendlyFeatures.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/AndroidFriendlyFeatures.java new file mode 100644 index 0000000..f49e6e3 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/AndroidFriendlyFeatures.java @@ -0,0 +1,34 @@ +package com.mi.showcase.util; + +import org.glassfish.hk2.api.Descriptor; +import org.glassfish.hk2.api.Filter; +import org.glassfish.hk2.utilities.binding.AbstractBinder; + +import javax.ws.rs.core.Feature; +import javax.ws.rs.core.FeatureContext; + +/** + * @author Sachith Dickwella + */ +public class AndroidFriendlyFeatures implements Feature { + + @Override + public boolean configure(FeatureContext context) { + context.register(new AbstractBinder() { + @Override + protected void configure() { + addUnbindFilter(new Filter() { + @Override + public boolean matches(Descriptor d) { + String implClass = d.getImplementation(); + return implClass.startsWith( + "org.glassfish.jersey.message.internal.DataSource") + || implClass.startsWith( + "org.glassfish.jersey.message.internal.RenderedImage"); + } + }); + } + }); + return true; + } +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/DialogTypes.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/DialogTypes.java new file mode 100644 index 0000000..1789743 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/DialogTypes.java @@ -0,0 +1,9 @@ +package com.mi.showcase.util; + +/** + * @author Sachith Dickwella + */ +public enum DialogTypes { + + CONNECTION_DIALOG, INFORMATION_DIALOG +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/MessageHandler.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/MessageHandler.java new file mode 100644 index 0000000..b8dd803 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/MessageHandler.java @@ -0,0 +1,29 @@ +package com.mi.showcase.util; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; + +/** + * @author Sachith Dickwella + */ +public class MessageHandler { + + public static Handler sendMessageHandler(Handler handler, String key, String messageBody) { + Bundle bundle = new Bundle(); + bundle.putString(key, messageBody); + + Message message = handler.obtainMessage(); + message.setData(bundle); + handler.sendMessage(message); + + return handler; + } + + public static Thread executeHandler(Runnable runnable) + throws InterruptedException { + Thread isolatedThread = new Thread(runnable); + isolatedThread.start(); + return isolatedThread; + } +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/ShowcaseUtils.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/ShowcaseUtils.java new file mode 100644 index 0000000..1d0c6c0 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/util/ShowcaseUtils.java @@ -0,0 +1,80 @@ +package com.mi.showcase.util; + +import android.app.Activity; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + +import com.mi.showcase.dialog.ConnectionDialog; +import com.mi.showcase.dialog.InformationDialog; +import com.mi.showcase.view.dto.MobileDataListModel; +import com.mi.showcase.view.dto.Model; + +/** + * @author Sachith Dickwella + */ +public abstract class ShowcaseUtils { + + public static boolean isConnected(Context context) { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = cm.getActiveNetworkInfo(); + + return networkInfo != null && networkInfo.isConnectedOrConnecting(); + } + + + public static class ShowcaseUtilDialogs { + + private final Activity context; + private final DialogTypes dialogTypes; + private InterceptionBeforeExecutor interceptionBeforeExecutor; + private InterceptionAfterExecutor interceptionAfterExecutor; + + public ShowcaseUtilDialogs(Activity context, DialogTypes dialogTypes, + InterceptionBeforeExecutor interceptionBeforeExecutor, + InterceptionAfterExecutor interceptionAfterExecutor) { + this.context = context; + this.dialogTypes = dialogTypes; + this.interceptionBeforeExecutor = interceptionBeforeExecutor; + this.interceptionAfterExecutor = interceptionAfterExecutor; + } + + public void showDialog(Model model) { + if (interceptionBeforeExecutor != null) { + interceptionBeforeExecutor.run(); + } + switch (dialogTypes) { + case CONNECTION_DIALOG: + ConnectionDialog connectionDialog = new ConnectionDialog(); + connectionDialog.show(context.getFragmentManager(), null); + break; + case INFORMATION_DIALOG: + InformationDialog informationDialog = new InformationDialog(); + informationDialog.setMobileDataListModel((MobileDataListModel)model); + informationDialog.show(context.getFragmentManager(), null); + break; + default: + break; + } + if (interceptionAfterExecutor != null) { + interceptionAfterExecutor.run(); + } + } + + public void setInterceptionBeforeExecutor(InterceptionBeforeExecutor interceptionBeforeExecutor) { + this.interceptionBeforeExecutor = interceptionBeforeExecutor; + } + + public void setInterceptionAfterExecutor(InterceptionAfterExecutor interceptionAfterExecutor) { + this.interceptionAfterExecutor = interceptionAfterExecutor; + } + + public interface InterceptionBeforeExecutor { + void run(); + } + + public interface InterceptionAfterExecutor { + void run(); + } + } +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/MobileDataAdapter.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/MobileDataAdapter.java new file mode 100644 index 0000000..6a0ae27 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/MobileDataAdapter.java @@ -0,0 +1,70 @@ +package com.mi.showcase.view; + +import android.app.Activity; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import com.mi.showcase.R; +import com.mi.showcase.view.dto.MobileDataListModel; + +import java.util.List; + +/** + * @author Sachith Dickwella + */ +public class MobileDataAdapter extends ArrayAdapter { + + private Activity context; + private List items; + + public MobileDataAdapter(Context context, List items) { + super(context, R.layout.entry_list_view, items); + this.context = (Activity) context; + this.items = items; + } + + @Override + public View getView(int position, View view, ViewGroup viewGroup) { + final ViewHolder viewHolder; + if (view == null) { + LayoutInflater inflater = context.getLayoutInflater(); + view = inflater.inflate(R.layout.entry_list_view, null, true); + + viewHolder = new ViewHolder(); + viewHolder.deviceName = (TextView) view.findViewById(R.id.deviceName); + viewHolder.androidName = (TextView) view.findViewById(R.id.osName); + viewHolder.version = (TextView) view.findViewById(R.id.version); + + view.setTag(R.id.deviceName, viewHolder.deviceName); + view.setTag(R.id.osName, viewHolder.androidName); + view.setTag(R.id.version, viewHolder.version); + view.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) view.getTag(); + } + + MobileDataListModel mobileDataListModel = getItem(position); + + viewHolder.deviceName.setText(mobileDataListModel.getDeviceName()); + viewHolder.androidName.setText(mobileDataListModel.getAndroidName()); + viewHolder.version.setText("ver. " + mobileDataListModel.getVersion()); + + return view; + } + + @Override + public MobileDataListModel getItem(int position) { + return this.items.get(position); + } + + private static class ViewHolder { + + private TextView deviceName; + private TextView androidName; + private TextView version; + } +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/dto/MobileDataListModel.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/dto/MobileDataListModel.java new file mode 100644 index 0000000..75f37b6 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/dto/MobileDataListModel.java @@ -0,0 +1,99 @@ +package com.mi.showcase.view.dto; + +/** + * @author Sachith Dickwella + */ +public class MobileDataListModel implements Model { + + private int id; + private String deviceName; + private String androidName; + private String version; + private String codeName; + private String distribution; + private String carrier; + private String snippet; + private String imageUrl; + private String target; + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getAndroidName() { + return androidName; + } + + public void setAndroidName(String androidName) { + this.androidName = androidName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getCodeName() { + return codeName; + } + + public void setCodeName(String codeName) { + this.codeName = codeName; + } + + public String getDistribution() { + return distribution; + } + + public void setDistribution(String distribution) { + this.distribution = distribution; + } + + public String getCarrier() { + return carrier; + } + + public void setCarrier(String carrier) { + this.carrier = carrier; + } + + public String getSnippet() { + return snippet; + } + + public void setSnippet(String snippet) { + this.snippet = snippet; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } +} diff --git a/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/dto/Model.java b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/dto/Model.java new file mode 100644 index 0000000..1db027a --- /dev/null +++ b/sachith_task/Showcase/app/src/main/java/com/mi/showcase/view/dto/Model.java @@ -0,0 +1,7 @@ +package com.mi.showcase.view.dto; + +/** + * @author Sachith Dickwella + */ +public interface Model { +} diff --git a/sachith_task/Showcase/app/src/main/res/drawable/image_background.xml b/sachith_task/Showcase/app/src/main/res/drawable/image_background.xml new file mode 100644 index 0000000..b9ecbd0 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/drawable/image_background.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/app/src/main/res/layout/activity_insert_data.xml b/sachith_task/Showcase/app/src/main/res/layout/activity_insert_data.xml new file mode 100644 index 0000000..0c37255 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/layout/activity_insert_data.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/res/layout/activity_show_case.xml b/sachith_task/Showcase/app/src/main/res/layout/activity_show_case.xml new file mode 100644 index 0000000..00e6339 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/layout/activity_show_case.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/res/layout/content_insert_data.xml b/sachith_task/Showcase/app/src/main/res/layout/content_insert_data.xml new file mode 100644 index 0000000..840be7b --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/layout/content_insert_data.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/res/layout/content_show_case.xml b/sachith_task/Showcase/app/src/main/res/layout/content_show_case.xml new file mode 100644 index 0000000..5e730d6 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/layout/content_show_case.xml @@ -0,0 +1,28 @@ + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/res/layout/dialog_information.xml b/sachith_task/Showcase/app/src/main/res/layout/dialog_information.xml new file mode 100644 index 0000000..9774fbb --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/layout/dialog_information.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sachith_task/Showcase/app/src/main/res/layout/entry_list_view.xml b/sachith_task/Showcase/app/src/main/res/layout/entry_list_view.xml new file mode 100644 index 0000000..69b5d6d --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/layout/entry_list_view.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/res/menu/menu_insert_data.xml b/sachith_task/Showcase/app/src/main/res/menu/menu_insert_data.xml new file mode 100644 index 0000000..489e3f8 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/menu/menu_insert_data.xml @@ -0,0 +1,11 @@ + + + diff --git a/sachith_task/Showcase/app/src/main/res/menu/menu_showcase.xml b/sachith_task/Showcase/app/src/main/res/menu/menu_showcase.xml new file mode 100644 index 0000000..ed03c97 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/menu/menu_showcase.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_accept.png b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_accept.png new file mode 100644 index 0000000..700fc81 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_accept.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_new.png b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_new.png new file mode 100644 index 0000000..d866d61 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_new.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_overflow.png b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_overflow.png new file mode 100644 index 0000000..c8792cb Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_overflow.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_phone.png b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_phone.png new file mode 100644 index 0000000..10970e7 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_action_phone.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_launcher.png b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_accept.png b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_accept.png new file mode 100644 index 0000000..41107b8 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_accept.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_new.png b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_new.png new file mode 100644 index 0000000..f17e798 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_new.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_overflow.png b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_overflow.png new file mode 100644 index 0000000..b4a4a22 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_overflow.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_phone.png b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_phone.png new file mode 100644 index 0000000..727f652 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_action_phone.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_launcher.png b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_accept.png b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_accept.png new file mode 100644 index 0000000..6ee32b6 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_accept.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_new.png b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_new.png new file mode 100644 index 0000000..dde2141 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_new.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_overflow.png b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_overflow.png new file mode 100644 index 0000000..5d8af5d Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_overflow.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_phone.png b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_phone.png new file mode 100644 index 0000000..bacfea1 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_action_phone.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_accept.png b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_accept.png new file mode 100644 index 0000000..68c41de Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_accept.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_new.png b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_new.png new file mode 100644 index 0000000..c42c2bf Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_new.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_overflow.png b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_overflow.png new file mode 100644 index 0000000..e22049b Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_overflow.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_phone.png b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_phone.png new file mode 100644 index 0000000..33cf354 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_action_phone.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/sachith_task/Showcase/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/sachith_task/Showcase/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/sachith_task/Showcase/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/sachith_task/Showcase/app/src/main/res/values-v21/styles.xml b/sachith_task/Showcase/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..251fb9f --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,9 @@ +> + + + diff --git a/sachith_task/Showcase/app/src/main/res/values-w820dp/dimens.xml b/sachith_task/Showcase/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/sachith_task/Showcase/app/src/main/res/values/colors.xml b/sachith_task/Showcase/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..6b5632b --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #00b300 + #008000 + #FF4000 + diff --git a/sachith_task/Showcase/app/src/main/res/values/dimens.xml b/sachith_task/Showcase/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..41bd048 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/values/dimens.xml @@ -0,0 +1,13 @@ + + + 0dp + 0dp + 8dp + 20dp + 18sp + 20sp + 15sp + 5dp + 22sp + 180dp + diff --git a/sachith_task/Showcase/app/src/main/res/values/strings.xml b/sachith_task/Showcase/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..e6019a4 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/values/strings.xml @@ -0,0 +1,60 @@ + + Showcase + Add Device + Settings + Showcase + Temporary Content + + + Unable to connect + Device Information + + + You need a network connection to use this app. + Please turn on Mobile Data or Wi-Fi in settings. + + + CANCLE + SETTINGS + OK + + + Overflow + Refresh + Save + + + MI Developer Android Solution + + + HTTP 503 Service Unavailable + Data saving process success + Data saving process failed + Some required fields are empty + + android + devices + dataStore.json + + + Code name:  + Distribution:  + Carrier:  + Version:  + None + + + + Device Name + Android Name + Carrier + Version + Target API + Code Name + Distribution + Remark + Image URL + + + % + diff --git a/sachith_task/Showcase/app/src/main/res/values/styles.xml b/sachith_task/Showcase/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..545b9c6 --- /dev/null +++ b/sachith_task/Showcase/app/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + +