multitenant
František Přibyl 11 years ago
commit 51a0de2d53

@ -40,7 +40,12 @@ public abstract class BaseDaoJPA<T> implements BaseDao<T> {
@Override @Override
public void delete(T entity) { public void delete(T entity) {
sessionFactory.getCurrentSession().delete(entity); try {
sessionFactory.getCurrentSession().delete(entity);
} catch (NonUniqueObjectException e) {
Object o = sessionFactory.getCurrentSession().merge(entity);
sessionFactory.getCurrentSession().delete(o);
}
} }
@Override @Override

@ -1,9 +1,16 @@
package info.bukova.isspst.data; package info.bukova.isspst.data;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
@Entity @Entity
@ -18,6 +25,14 @@ public class Building extends BaseData implements DataModel {
@Column(name = "DESCRIPTION") @Column(name = "DESCRIPTION")
private String description; private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "building", orphanRemoval = true)
@LazyCollection(LazyCollectionOption.FALSE)
private List<Room> rooms;
public Building() {
rooms = new ArrayList<Room>();
}
/** /**
* @return the code * @return the code
@ -64,4 +79,22 @@ public class Building extends BaseData implements DataModel {
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public List<Room> getRooms() {
return rooms;
}
public void setRooms(List<Room> rooms) {
this.rooms = rooms;
}
public void addRoom(Room room) {
room.setBuilding(this);
rooms.add(room);
}
public void removeRoom(Room room) {
rooms.remove(room);
}
} }

@ -0,0 +1,94 @@
package info.bukova.isspst.data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "ROOM")
public class Room {
@Id
@Column(name = "ID")
@GeneratedValue
private int id;
@Column(name = "CODE")
private String code;
@Column(name = "SHORTCUT")
private String shortcut;
@Column(name = "NAME")
private String name;
@Column(name = "FLOOR")
private Integer floor;
@Column(name = "NUMBER")
private Integer number;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "BUILDING_ID")
private Building building;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getShortcut() {
return shortcut;
}
public void setShortcut(String shortcut) {
this.shortcut = shortcut;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getFloor() {
return floor;
}
public void setFloor(Integer floor) {
this.floor = floor;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public Building getBuilding() {
return building;
}
public void setBuilding(Building building) {
this.building = building;
}
public boolean equals(Object o) {
return ((o instanceof Room) && (((Room)o).getId() == this.getId()));
}
}

@ -1,9 +1,13 @@
package info.bukova.isspst.ui.buildings; package info.bukova.isspst.ui.buildings;
import info.bukova.isspst.data.Building; import info.bukova.isspst.data.Building;
import info.bukova.isspst.data.Room;
import info.bukova.isspst.ui.FormViewModel; import info.bukova.isspst.ui.FormViewModel;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
public class BuildingForm extends FormViewModel<Building> { public class BuildingForm extends FormViewModel<Building> {
@ -11,5 +15,18 @@ public class BuildingForm extends FormViewModel<Building> {
public void init() { public void init() {
} }
@Command
@NotifyChange("dataBean")
public void addRoom() {
Room r = new Room();
getDataBean().addRoom(r);
}
@Command
@NotifyChange("dataBean")
public void removeRoom(@BindingParam("room") Room room) {
getDataBean().getRooms().remove(room);
}
} }

@ -124,7 +124,7 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
return; return;
} }
getDataBean().removeMember(u); workgroupService.removeMember(getDataBean(), u);
if (!target.equals("users")) { if (!target.equals("users")) {
moveUser(u.getMember(), event); moveUser(u.getMember(), event);

@ -11,6 +11,7 @@
<mapping class="info.bukova.isspst.data.BaseData"></mapping> <mapping class="info.bukova.isspst.data.BaseData"></mapping>
<mapping class="info.bukova.isspst.data.Address"></mapping> <mapping class="info.bukova.isspst.data.Address"></mapping>
<mapping class="info.bukova.isspst.data.Building"></mapping> <mapping class="info.bukova.isspst.data.Building"></mapping>
<mapping class="info.bukova.isspst.data.Room"></mapping>
<mapping class="info.bukova.isspst.data.MUnit"></mapping> <mapping class="info.bukova.isspst.data.MUnit"></mapping>
<mapping class="info.bukova.isspst.data.Material"></mapping> <mapping class="info.bukova.isspst.data.Material"></mapping>
<mapping class="info.bukova.isspst.data.Workgroup"></mapping> <mapping class="info.bukova.isspst.data.Workgroup"></mapping>

@ -23,6 +23,11 @@ zipCode=PSČ
#Budova #Budova
code=Kód code=Kód
name=Název name=Název
rooms=Místnosti
#Místnost
shortcut=Zkratka
number=Číslo
floor=Podlaží
#Uživatel #Uživatel
accountNonExpired=Platný accountNonExpired=Platný

@ -48,9 +48,13 @@ BuildingsFormTitle=Budova
BuildingsFormCode=Kód BuildingsFormCode=Kód
BuildingsFormName=Název BuildingsFormName=Název
BuildingsFormDescription=Popis BuildingsFormDescription=Popis
BuildingsFormAddRoom=Přidat místnost
BuildingsFormRemove=Odstranit
BuildingsGridColumnCode=Kód BuildingsGridColumnCode=Kód
BuildingsGridColumnName=Název BuildingsGridColumnName=Název
BuildingsGridColumnDescription=Popis BuildingsGridColumnDescription=Popis
BuildingsGridRooms=Místnosti:
AgendaRooms=Místnosti AgendaRooms=Místnosti

@ -67,7 +67,7 @@
<rows> <rows>
<template name="model" var="member"> <template name="model" var="member">
<row visible="@load(member.role eq each)"> <row visible="@load(member.role eq each)">
<label value="@load(member.member.fullName)"/> <hbox><image src="/img/user-small-red.png"/><label value="@load(member.member.fullName)"/></hbox>
</row> </row>
</template> </template>
</rows> </rows>

@ -33,7 +33,7 @@
<menuitem label="${labels.AgendaServices}" href="/lists/service" disabled="${not sec:isAllGranted('PERM_READ_SERVICES')}"/> <menuitem label="${labels.AgendaServices}" href="/lists/service" disabled="${not sec:isAllGranted('PERM_READ_SERVICES')}"/>
<menuitem label="${labels.AgendaMUnits}" href="/lists/munits" disabled="${not sec:isAllGranted('PERM_READ_MUNITS')}" width="120px"/> <menuitem label="${labels.AgendaMUnits}" href="/lists/munits" disabled="${not sec:isAllGranted('PERM_READ_MUNITS')}" width="120px"/>
<menuitem label="${labels.AgendaBuildings}" href="/lists/buildings" disabled="${not sec:isAllGranted('PERM_READ_BUILDINGS')}" /> <menuitem label="${labels.AgendaBuildings}" href="/lists/buildings" disabled="${not sec:isAllGranted('PERM_READ_BUILDINGS')}" />
<menuitem label="${labels.AgendaRooms}" href="/lists/rooms" disabled="${not sec:isAllGranted('PERM_READ_ROOMS')}" /> <!-- <menuitem label="${labels.AgendaRooms}" href="/lists/rooms" disabled="${not sec:isAllGranted('PERM_READ_ROOMS')}" /> -->
</menubar> </menubar>
</tabpanel> </tabpanel>
<tabpanel> <tabpanel>

@ -5,54 +5,79 @@
<caption zclass="form-caption" label="${labels.AgendaBuildings}" /> <caption zclass="form-caption" label="${labels.AgendaBuildings}" />
<include src="/app/toolbar.zul" /> <include src="/app/toolbar.zul" />
<listbox model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)"> <hbox width="100%">
<listhead menupopup="auto"> <listbox model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)" hflex="4">
<listheader label="${labels.BuildingsGridColumnCode}" sort="czech(code)" width="10%" /> <listhead menupopup="auto">
<listheader label="${labels.BuildingsGridColumnName}" sort="czech(name)" width="30%" /> <listheader label="${labels.BuildingsGridColumnCode}" sort="czech(code)" width="10%" />
<listheader label="${labels.BuildingsGridColumnDescription}" sort="czech(description)" width="60%" /> <listheader label="${labels.BuildingsGridColumnName}" sort="czech(name)" width="30%" />
</listhead> <listheader label="${labels.BuildingsGridColumnDescription}" sort="czech(description)" width="60%" />
</listhead>
<auxhead sclass="category-center" visible="@load(vm.filter)">
<auxheader> <auxhead sclass="category-center" visible="@load(vm.filter)">
<div sclass="find-grid-cell"> <auxheader>
<div sclass="find-grid-divtextbox"> <div sclass="find-grid-cell">
<textbox value="@bind(vm.filterTemplate.code)" instant="true" onChange="@command('doFilter')" sclass="find-grid-textbox" /> <div sclass="find-grid-divtextbox">
<textbox value="@bind(vm.filterTemplate.code)" instant="true" onChange="@command('doFilter')" sclass="find-grid-textbox" />
</div>
<div sclass="find-grid-img">
<image src="/img/funnel.png" />
</div>
</div> </div>
<div sclass="find-grid-img"> </auxheader>
<image src="/img/funnel.png" /> <auxheader>
<div sclass="find-grid-cell">
<div sclass="find-grid-divtextbox">
<textbox value="@bind(vm.filterTemplate.name)" instant="true" onChange="@command('doFilter')" sclass="find-grid-textbox" />
</div>
<div sclass="find-grid-img">
<image src="/img/funnel.png" />
</div>
</div> </div>
</div> </auxheader>
</auxheader> <auxheader>
<auxheader> <div sclass="find-grid-cell">
<div sclass="find-grid-cell"> <div sclass="find-grid-divtextbox">
<div sclass="find-grid-divtextbox"> <textbox value="@bind(vm.filterTemplate.description)" instant="true" onChange="@command('doFilter')" sclass="find-grid-textbox" />
<textbox value="@bind(vm.filterTemplate.name)" instant="true" onChange="@command('doFilter')" sclass="find-grid-textbox" /> </div>
<div sclass="find-grid-img">
<image src="/img/funnel.png" />
</div>
</div> </div>
<div sclass="find-grid-img"> </auxheader>
<image src="/img/funnel.png" /> </auxhead>
</div>
</div> <template name="model">
</auxheader> <listitem>
<auxheader> <listcell label="@load(each.code)" />
<div sclass="find-grid-cell"> <listcell label="@load(each.name)" />
<div sclass="find-grid-divtextbox"> <listcell label="@load(each.description)" />
<textbox value="@bind(vm.filterTemplate.description)" instant="true" onChange="@command('doFilter')" sclass="find-grid-textbox" /> </listitem>
</div> </template>
<div sclass="find-grid-img"> </listbox>
<image src="/img/funnel.png" /> <vbox>
</div> <label value="${labels.BuildingsGridRooms}"/>
</div> <grid model="@load(vm.dataBean.rooms)" hflex="6">
</auxheader> <columns menupopup="auto">
</auxhead> <column label="${labels.code}"/>
<column label="${labels.name}"/>
<template name="model"> <column label="${labels.shortcut}"/>
<listitem> <column label="${labels.number}"/>
<listcell label="@load(each.code)" /> <column label="${labels.floor}"/>
<listcell label="@load(each.name)" /> </columns>
<listcell label="@load(each.description)" /> <rows>
</listitem> <template name="model">
</template> <row>
</listbox> <label value="@bind(each.code)"/>
<label value="@bind(each.name)"/>
<label value="@bind(each.shortcut)"/>
<label value="@bind(each.number)"/>
<label value="@bind(each.floor)"/>
</row>
</template>
</rows>
</grid>
</vbox>
</hbox>
</window> </window>
</zk> </zk>

@ -1,6 +1,7 @@
<?page title="${labels.BuildingsFormTitle}" contentType="text/html;charset=UTF-8"?> <?page title="${labels.BuildingsFormTitle}" contentType="text/html;charset=UTF-8"?>
<zk> <zk>
<window id="editWin" closable="true" border="normal" position="center" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('info.bukova.isspst.ui.buildings.BuildingForm')"> <window id="editWin" closable="true" border="normal" position="center" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.buildings.BuildingForm')" width="750px">
<caption src="/img/building.png" zclass="form-caption" label="${labels.BuildingsFormTitle}" /> <caption src="/img/building.png" zclass="form-caption" label="${labels.BuildingsFormTitle}" />
<vlayout> <vlayout>
<grid hflex="min"> <grid hflex="min">
@ -29,6 +30,27 @@
</row> </row>
</rows> </rows>
</grid> </grid>
<button image="/img/item-add.png" label="${labels.BuildingsFormAddRoom}" onClick="@command('addRoom')"/>
<listbox model="@load(vm.dataBean.rooms)">
<listhead>
<listheader label="${labels.code}"/>
<listheader label="${labels.name}"/>
<listheader label="${labels.shortcut}"/>
<listheader label="${labels.number}"/>
<listheader label="${labels.floor}"/>
<listheader/>
</listhead>
<template name="model">
<listitem>
<listcell><textbox inplace="true" value="@bind(each.code)"/></listcell>
<listcell><textbox inplace="true" value="@bind(each.name)"/></listcell>
<listcell><textbox inplace="true" value="@bind(each.shortcut)"/></listcell>
<listcell><textbox inplace="true" value="@bind(each.number)"/></listcell>
<listcell><textbox inplace="true" value="@bind(each.floor)"/></listcell>
<listcell><button image="/img/item-remove.png" label="${labels.BuildingsFormRemove}" onClick="@command('removeRoom', room=each)"/></listcell>
</listitem>
</template>
</listbox>
<include src="/app/formButtons.zul" /> <include src="/app/formButtons.zul" />
</vlayout> </vlayout>
</window> </window>

Loading…
Cancel
Save