1
|
1 package de.mpiwg.itgroup.ismi.entry.beans;
|
|
2
|
|
3 import java.util.ArrayList;
|
|
4 import java.util.List;
|
|
5
|
|
6 import javax.faces.model.SelectItem;
|
|
7
|
|
8 import org.apache.log4j.Logger;
|
|
9 import org.mpi.openmind.repository.bo.Entity;
|
|
10 import org.mpi.openmind.repository.bo.Node;
|
|
11 import org.mpi.openmind.repository.bo.Relation;
|
125
|
12 import org.mpi.openmind.repository.services.utils.EditIntent;
|
1
|
13 import org.mpi.openmind.security.bo.User;
|
|
14
|
|
15
|
|
16 public class CurrentSubjectBean extends AbstractISMIBean {
|
|
17
|
|
18 private static final long serialVersionUID = -435164522506185752L;
|
|
19
|
|
20 private static Logger logger = Logger.getLogger(CurrentSubjectBean.class);
|
|
21
|
|
22 public static String type = "type";
|
|
23 public static String NO_SUBJECT = "NO_SUBJECT";
|
|
24
|
|
25 public static String has_subject = "has_subject";
|
|
26 public static String SUBJECT = "SUBJECT";
|
|
27 public static String main_subject = "main_subject";
|
|
28 public static String sub_subject = "sub_subject";
|
|
29
|
|
30 private Long idMainSubject;
|
|
31
|
|
32 private List<SelectItem> suggestedCategories = new ArrayList<SelectItem>();
|
|
33 private List<SelectItem> suggestedTypes = new ArrayList<SelectItem>();
|
|
34
|
125
|
35 /** intent to edit all attributes and relations in the form */
|
|
36 public static EditIntent editSubjectIntent = new EditIntent(
|
|
37 AbstractISMIBean.SUBJECT,
|
|
38 // attributes
|
|
39 new String[]{"name", "type"},
|
|
40 // source relations
|
|
41 new String[]{"is_part_of"},
|
|
42 // target relations
|
|
43 new String[]{"is_part_of"});
|
|
44
|
1
|
45 public CurrentSubjectBean(){
|
|
46 suggestedTypes.add(new SelectItem(null, "-- choose --"));
|
|
47 suggestedTypes.add(new SelectItem(main_subject, main_subject));
|
|
48 suggestedTypes.add(new SelectItem(sub_subject, sub_subject));
|
|
49 reset();
|
|
50 }
|
|
51
|
|
52 @Override
|
|
53 public void reset(){
|
|
54 super.reset();
|
|
55 this.entity = new Entity(Node.TYPE_ABOX, SUBJECT, false);
|
|
56
|
|
57 setDefObjectClass(SUBJECT);
|
|
58 this.idMainSubject = null;
|
|
59
|
|
60 this.suggestedCategories = new ArrayList<SelectItem>();
|
|
61 this.suggestedCategories.add(new SelectItem(null, "-- choose --"));
|
|
62
|
|
63 List<Entity> cats = getWrapper().getEntitiesByAtt(SUBJECT, type, main_subject, -1, true);
|
|
64
|
|
65 for(Entity cat : cats){
|
|
66 SelectItem item = new SelectItem(cat.getId(), cat.getOwnValue());
|
|
67
|
|
68 item.setStyle("font-weight: bold; padding-left: 0px; font-size: 14;");
|
|
69 this.suggestedCategories.add(item);
|
|
70 List<Entity> subCats = getWrapper().getSourcesForTargetRelation(cat, is_part_of, SUBJECT, -1);
|
|
71 for(Entity subCat : subCats){
|
|
72
|
|
73 SelectItem subItem = new SelectItem(subCat.getId(), subCat.getOwnValue());
|
|
74 subItem.setStyle("padding-left: 10px; font-size: 12;");
|
|
75
|
|
76 this.suggestedCategories.add(subItem);
|
|
77 List<Entity> subsubCats = getWrapper().getSourcesForTargetRelation(subCat, is_part_of, SUBJECT, -1);
|
|
78 for(Entity subsubCat : subsubCats){
|
|
79
|
|
80 SelectItem subsubItem = new SelectItem(subsubCat.getId(), subsubCat.getOwnValue());
|
|
81 subsubItem.setStyle("padding-left: 20px; font-size: 10;");
|
|
82 this.suggestedCategories.add(subsubItem);
|
|
83 }
|
|
84 }
|
|
85 }
|
|
86 }
|
|
87
|
|
88 public void setEntity(Entity subject) {
|
|
89 this.reset();
|
|
90
|
|
91 this.entity = subject;
|
|
92 if(this.entity.isPersistent()){
|
|
93 this.setCurrentId(this.entity.getId().toString());
|
|
94 if (subject.isLightweight()) {
|
|
95 this.entity = getWrapper().getEntityContent(this.entity);
|
|
96 }
|
|
97 this.loadAttributes(this.entity);//, getDefinition(this.entity));
|
|
98
|
|
99 for (Relation rel : this.entity.getSourceRelations()) {
|
|
100 if(rel.getOwnValue().equals(is_part_of)){
|
|
101 this.idMainSubject = rel.getTargetId();
|
|
102 }
|
|
103 }
|
|
104 }
|
|
105 }
|
|
106
|
|
107 @Override
|
|
108 public String save() {
|
|
109 super.save();
|
|
110 try {
|
|
111 User user = getSessionUser();
|
|
112
|
|
113 this.entity = updateEntityAttributes(this.entity);
|
|
114
|
|
115 this.entity.removeAllSourceRelations(is_part_of, SUBJECT);
|
|
116 if(getIdMainSubject() != null){
|
|
117 Entity mainCategory = getWrapper().getEntityById(getIdMainSubject());
|
|
118 //replaceSourceRelation(this.entity, mainCategory, SUBJECT, is_part_of);
|
125
|
119 if (mainCategory.isLightweight()) {
|
|
120 mainCategory = getWrapper().getEntityContent(mainCategory);
|
|
121 }
|
1
|
122 this.entity.replaceSourceRelation(mainCategory, SUBJECT, is_part_of);
|
|
123 }
|
|
124
|
125
|
125 this.entity = getWrapper().saveEntity(this.entity, user.getEmail(), editSubjectIntent);
|
1
|
126 getSessionBean().setEditFormCurrentEntId(this.entity.getId());
|
|
127
|
|
128 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity);
|
|
129 this.printSuccessSavingEntity();
|
|
130
|
|
131 getAppBean().resetSuggestedSubjects();
|
|
132 } catch (Exception e) {
|
|
133 logger.error(e.getMessage(), e);
|
|
134 this.printInternalError(e);
|
|
135 }
|
|
136
|
|
137 saveEnd();
|
|
138 return PAGE_EDITOR;
|
|
139
|
|
140 }
|
|
141
|
|
142 public List<SelectItem> getSuggestedCategories() {
|
|
143 return suggestedCategories;
|
|
144 }
|
|
145
|
|
146 public void setSuggestedCategories(List<SelectItem> suggestedCategories) {
|
|
147 this.suggestedCategories = suggestedCategories;
|
|
148 }
|
|
149
|
|
150 public Long getIdMainSubject() {
|
|
151 return idMainSubject;
|
|
152 }
|
|
153
|
|
154 public void setIdMainSubject(Long idMainSubject) {
|
|
155 this.idMainSubject = idMainSubject;
|
|
156 }
|
|
157
|
|
158 public List<SelectItem> getSuggestedTypes() {
|
|
159 return suggestedTypes;
|
|
160 }
|
|
161
|
|
162 public void setSuggestedTypes(List<SelectItem> suggestedTypes) {
|
|
163 this.suggestedTypes = suggestedTypes;
|
|
164 }
|
|
165 }
|