1 package ru
.rentdom
.pages
.cabinet
;
6 import javax
.servlet
.http
.HttpServletResponse
;
8 import net
.aramzamzam
.commons
.components
.utils
.select
.InjectSelectionModel
;
9 import net
.aramzamzam
.commons
.pagesbehavoir
.services
.HttpStatusCode
;
11 import org
.apache
.commons
.lang
.ArrayUtils
;
12 import org
.apache
.tapestry5
.Block
;
13 import org
.apache
.tapestry5
.PersistenceConstants
;
14 import org
.apache
.tapestry5
.annotations
.Persist
;
15 import org
.apache
.tapestry5
.annotations
.Property
;
16 import org
.apache
.tapestry5
.hibernate
.annotations
.CommitAfter
;
17 import org
.apache
.tapestry5
.ioc
.annotations
.Inject
;
19 import ru
.rentdom
.entities
.coords
.District
;
20 import ru
.rentdom
.entities
.coords
.MetroStation
;
21 import ru
.rentdom
.entities
.coords
.Town
;
22 import ru
.rentdom
.entities
.housing
.Housing
;
23 import ru
.rentdom
.services
.coords
.CoordsService
;
24 import ru
.rentdom
.services
.housing
.HousingService
;
25 import ru
.rentdom
.utils
.Authority
;
26 import ru
.rentdom
.utils
.HousingType
;
27 import ru
.rentdom
.utils
.RoleConstants
;
30 public class Edit
extends AbstractCabinetPage
{
33 @Persist(PersistenceConstants
.FLASH
)
34 private Housing housing
;
37 private Block activeBlock
;
40 private Block blockHousingType
;
43 private Block blockEditor
;
46 private CoordsService coordsService
;
48 @SuppressWarnings("unused")
49 @InjectSelectionModel(labelField
= "name", idField
= "id")
50 private List
<Town
> towns
;
52 @SuppressWarnings("unused")
53 @InjectSelectionModel(labelField
= "name", idField
= "id")
54 private List
<District
> districts
;
56 @InjectSelectionModel(labelField
= "name", idField
= "id")
57 private List
<MetroStation
> metros
;
60 private HousingService housingService
;
62 void onActivate(Town town
, HousingType type
)
64 if (housing
!=null && housing
.getId()==null)
66 housing
.setType(type
);
67 housing
.setTown(town
);
68 housing
.setOwner(getCurrentUser());
69 housing
.setCreated(new Date());
72 districts
=coordsService
.findAllDistricts(town
);
73 metros
=coordsService
.findAllMetroStations(town
);
74 activeBlock
=blockEditor
;
77 Object
onActivate(Town town
, HousingType type
, Housing housing
)
80 || (!housing
.getOwner().equals(getCurrentUser())
81 && !ArrayUtils
.contains(getCurrentUser().getAuthorities(), new Authority(RoleConstants
.ADMIN
))))
82 return new HttpStatusCode(HttpServletResponse
.SC_NOT_FOUND
, "Requested resource was not found");
90 if (activeBlock
==null)
92 housing
=new Housing();
93 towns
=coordsService
.findAllTowns();
94 activeBlock
=blockHousingType
;
99 Object
[] onPassivate()
101 if (housing
==null || housing
.getTown()==null || housing
.getType()==null)
103 if (housing
.getId()!=null)
104 return new Object
[]{housing
.getTown(), housing
.getType(), housing
};
106 return new Object
[]{housing
.getTown(), housing
.getType()};
109 public boolean isHasMetro()
111 return metros
.size()>0;
115 Object
onSuccessFromFormEditor()
117 housing
.setUpdated(new Date());
118 housingService
.save(housing
);