Skip to content

Commit

Permalink
Create MODELS for products and repair
Browse files Browse the repository at this point in the history
  • Loading branch information
FairWindCo committed Oct 15, 2015
1 parent 8aaa625 commit adc7c23
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.model.Person;
import ua.pp.fairwind.favorid.internalDB.model.administrative.Role;
import ua.pp.fairwind.favorid.internalDB.model.administrative.User;
import ua.pp.fairwind.favorid.internalDB.repository.PersonRepository;
import ua.pp.fairwind.favorid.internalDB.repository.RoleRepository;
import ua.pp.fairwind.favorid.internalDB.repository.UserRepository;

Expand All @@ -34,6 +36,8 @@ public class UserController {
UserRepository userRepository;
@Autowired
RoleRepository roleRepository;
@Autowired
PersonRepository personRepository;

@Secured("ROLE_USER")
@RequestMapping(value = "/list", method = RequestMethod.GET)
Expand Down Expand Up @@ -115,17 +119,56 @@ public List<Role> getAvaibleRoles(@RequestParam long userID){

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,User user,BindingResult result,HttpServletResponse response)throws IOException{
public void editor(@RequestParam String oper,User user,BindingResult result,HttpServletRequest request,HttpServletResponse response)throws IOException{
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
switch (oper){
case "add":
case "edit":
String pk=request.getParameter("person_id_primary_key");
if(pk!=null){
try {
Long pid=Long.getLong(pk);
Person person=personRepository.findOne(pid);
if(person!=null){
user.setPerson(person);
}
}catch (NumberFormatException e){
//do nothing
}
}
userRepository.save(user);
response.setStatus(200);
break;
case "edit":
User usr=userRepository.getOne(user.getUserID());
if(usr!=null) {
if( usr.getVersionId() <= user.getVersionId()) {
usr.setEnabled(user.isEnabled());
usr.setPasswordHash(user.getPasswordHash());
usr.setUserName(user.getUserName());
String pkey=request.getParameter("person_id_primary_key");
if(pkey!=null) {
try {
Long pid = Long.getLong(pkey);
Person person = personRepository.findOne(pid);
if (person != null) {
usr.setPerson(person);
}
} catch (NumberFormatException e) {
//do nothing
}
}
userRepository.save(usr);
response.setStatus(200);
} else {
response.sendError(400, "ANOTHER TRANSACTION MODIFICATION");
}
} else {
response.sendError(404, "NO USER WITH ID " + user.getUserID() + " FOUND");
}
break;
case "del":
userRepository.delete(user.getUserID());
response.setStatus(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Created by Ñåðãåé on 06.10.2015.
*/
@Entity
@Table(name = "USER_ROELS")
@Table(name = "USER_ROLES")
public class Role {
@Id
@GeneratedValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ua.pp.fairwind.favorid.internalDB.model.administrative;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import ua.pp.fairwind.favorid.internalDB.model.Person;

import javax.persistence.*;
Expand All @@ -28,13 +28,24 @@ public class User {
@ManyToMany(fetch = FetchType.EAGER)
private Set<Role> userRoles=new HashSet<>();

@JsonManagedReference
@ManyToOne
@JsonIgnore
@JoinColumn(name = "person_id")
private Person person;
@Version
private long versionId;

@JsonSerialize
public String getFIO(){
if(person==null) return null;
return person.getSurname()==null?"":person.getSurname()+" "+person.getFirstName()==null?"":person.getFirstName()+" "+person.getMiddleName()==null?"":person.getMiddleName();
}

@JsonSerialize
public Long getPersonID(){
return person==null?null:person.getId();
}

public Long getUserID() {
return userID;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ua.pp.fairwind.favorid.internalDB.model.products;

import ua.pp.fairwind.favorid.internalDB.model.Document;
import ua.pp.fairwind.favorid.internalDB.model.storehouses.Nomenclature;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
* Created by Ñåðãåé on 15.10.2015.
*/
@Entity
@Table(name = "PRODUCTS")
public class Product {
@Id
@GeneratedValue
Long id;
@ManyToOne
@JoinColumn(name = "nomenclature_ID")
Nomenclature nomenclature;
String serial_number;
boolean self_created=false;
String description;
@OneToMany
Set<Document> productDocuments=new HashSet<>();
@ManyToOne
@JoinColumn(name = "composed_ID")
Product composedOf;
@OneToMany(mappedBy = "composedOf")
Set<Product> composition=new HashSet<>();
Date createdDate;
Date shippingDate;
Date guaranteePeriod;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ua.pp.fairwind.favorid.internalDB.model.products;

/**
* Created by Ñåðãåé on 15.10.2015.
*/
public enum REPAIR_STATUS {
ENTRY,
TROUBLESHOOTING,
WAITING_FOR_PARTS,
REJECTED,
RESTORED,
SENT_TO_MANUFACTURER,
SERVICE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ua.pp.fairwind.favorid.internalDB.model.products;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
* Created by Ñåðãåé on 15.10.2015.repairs
*/
@Entity
@Table(name = "REPAIRS")
public class Repair {
@Id
@GeneratedValue
Long id;
@ManyToOne
@JoinColumn(name = "product_ID")
Product product;
String description;
String repairResult;
REPAIR_STATUS status;
Date start=new Date();
Date end;
Date lastStatusChange;
@OneToMany(mappedBy = "repair")
Set<RepairIteration> repairIteration=new HashSet<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ua.pp.fairwind.favorid.internalDB.model.products;

import javax.persistence.*;
import java.util.Date;

/**
* Created by Ñåðãåé on 15.10.2015.
*/
@Entity
public class RepairIteration {
@Id
@GeneratedValue
Long id;
@ManyToOne
@JoinColumn(name = "repair_ID")
Repair repair;
REPAIR_STATUS status;
String description;
Date created=new Date();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public interface PersonRepository extends JpaRepository<Person,Long>{
@Query("Select new ua.pp.fairwind.favorid.internalDB.model.proxy.PersonProxy(p.id,p.surname,p.firstName,p.middleName,p.date_of_birth) from Person p where p.counterparty.id=:firmID")
List<PersonProxy> findProxyByFirm(@Param("firmID")long firmID,Sort sort);

@Query("select c from Contact c,Person p where f.id=:ID and c member of p.contacts")
@Query("select c from Contact c,Person p where p.id=:ID and c member of p.contacts")
Page<Contact> getContacts(@Param("ID") long id, Pageable pager);
@Query("select c from Contact c,Person p where f.id=:ID and c member of p.contacts")
@Query("select c from Contact c,Person p where p.id=:ID and c member of p.contacts")
List<Contact> getContacts(@Param("ID") long id);
}
19 changes: 15 additions & 4 deletions src/main/webapp/WEB-INF/jpaContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,21 @@
-->
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>

<!-- spring based scanning for entity classes>
<property name="packagesToScan" value="ua.pp.fairwind.favorid.internalDB.model"/>
-->
<property name="packagesToScan" value="ua.pp.fairwind.favorid.internalDB.model"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property>

<!-- spring based scanning for entity classes>-->
<property name="packagesToScan">
<array>
<value>ua.pp.fairwind.favorid.internalDB.model</value>
<value>ua.pp.fairwind.favorid.internalDB.model.products</value>
<value>ua.pp.fairwind.favorid.internalDB.model.storehouses</value>
</array>
</property>
</bean>


Expand Down
35 changes: 33 additions & 2 deletions src/main/webapp/jsp/user_list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<!-- Bootstrap Core JavaScript -->
<%@include file="/include/bootstrup_include.jsp" %>
<%@include file="/include/jgrid_include.jsp" %>
<%-- jquery.ajax-combobox --%>
<%@include file="/include/select_include.jsp" %>

</head>
<body>
Expand Down Expand Up @@ -53,13 +55,42 @@
datatype: 'json',
mtype: 'POST',
styleUI : 'Bootstrap',
colNames:['<c:message code="label.id"/>', '<c:message code="label.usertables.table.col_title.login"/>', '<c:message code="label.usertables.table.col_title.password"/>','<c:message code="label.user.enabled"/>', '<c:message code="label.version"/>'],
colNames:['<c:message code="label.id"/>', '<c:message code="label.usertables.table.col_title.login"/>', '<c:message code="label.usertables.table.col_title.password"/>','<c:message code="label.user.enabled"/>', '<c:message code="label.version"/>','<c:message code="label.user.person_name"/>','<c:message code="label.user.person_name"/>'],
colModel:[
{name:'userID',index:'userID', width:55, editable:false, editoptions:{readonly:true, size:10}, hidden:true},
{name:'userID',index:'userID', width:55, editable:true, editoptions:{readonly:true, size:10}, hidden:true},
{name:'userName',index:'userName', width:100, editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'passwordHash',index:'passwordHash', width:100, editable:true, editrules:{required:true}, editoptions:{size:10},search:false},
{name:'enabled',index:'numberFormat', width:100, editable:true, editrules:{required:true}, editoptions:{size:10},search:false},
{name:'versionId',index:'versionID', width:100, editable:true, editrules:{readonly:true}, editoptions:{size:10,defaultValue:'0'}, hidden:true},
{name:'FIO',width:100, editable:false, search:false},
{name:'personID',width:100, editable:true, search:false, hidden:true, editrules:{edithidden:true},editable:true,editoptions:{
/**/
dataInit : function (elem) {
var value_elem=$(elem).val();
$(elem).wrap("<div></div>");
$(elem).width='80px';
$(elem).ajaxComboBox('${pageContext.request.contextPath}/persons/showList?firmID=1',
{lang: 'en',
db_table: 'nation',
per_page: 20,
navi_num: 10,
select_only: true,
primary_key: 'id',
show_field: 'surname,middleName,firstName',
field:'surname',
//recalc_width:false,
button_img:'${pageContext.request.contextPath}/resources/images/btn.png',
init_record: [value_elem],
sub_info: true,
/**/
sub_as: {
surname: 'surname',
middleName: 'middleName',
firstName:'firstName'
}/**/
});
}/**/
}},
],
rowNum:10,
rowList:[10,20,40,60],
Expand Down

0 comments on commit adc7c23

Please sign in to comment.