Rev 1766 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1766 | Rev 1776 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.services.data.repositorydocuments; |
1 | package pt.estgp.estgweb.services.data.repositorydocuments; |
2 | 2 | ||
3 | import com.owlike.genson.TransformationException; |
- | |
4 | import jomm.dao.impl.AbstractDao; |
3 | import jomm.dao.impl.AbstractDao; |
5 | import org.json.JSONArray; |
4 | import org.json.JSONArray; |
6 | import org.json.JSONException; |
5 | import org.json.JSONException; |
7 | import org.json.JSONObject; |
6 | import org.json.JSONObject; |
8 | import pt.estgp.estgweb.Globals; |
7 | import pt.estgp.estgweb.Globals; |
Line 40... | Line 39... | ||
40 | * |
39 | * |
41 | * @param newCollectionId new parent Collection Id |
40 | * @param newCollectionId new parent Collection Id |
42 | * @param documentIds documentIds: [LONG,LONG, ...] |
41 | * @param documentIds documentIds: [LONG,LONG, ...] |
43 | * @param userSession |
42 | * @param userSession |
44 | * @throws IOException |
43 | * @throws IOException |
45 | * @throws TransformationException |
- | |
46 | * @throws JSONException |
44 | * @throws JSONException |
47 | * @throws AccessDeniedException |
45 | * @throws AccessDeniedException |
48 | */ |
46 | */ |
49 | public void changeDocumentCollection(1.5.0/docs/api/java/lang/Long.html">Long newCollectionId , JSONArray documentIds, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException |
47 | public void changeDocumentCollection(1.5.0/docs/api/java/lang/Long.html">Long newCollectionId , JSONArray documentIds, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException |
50 | { |
48 | { |
51 | RepositoryDocumentCollection newCollection = DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(newCollectionId); |
49 | RepositoryDocumentCollection newCollection = DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(newCollectionId); |
52 | for(int i = 0; i < documentIds.length();i++) |
50 | for(int i = 0; i < documentIds.length();i++) |
53 | { |
51 | { |
54 | long documentId = documentIds.getLong(i); |
52 | long documentId = documentIds.getLong(i); |
Line 66... | Line 64... | ||
66 | * Uses Roles to filter collections |
64 | * Uses Roles to filter collections |
67 | * @param collectionId |
65 | * @param collectionId |
68 | * @param userSession |
66 | * @param userSession |
69 | * @return |
67 | * @return |
70 | * @throws IOException |
68 | * @throws IOException |
71 | * @throws TransformationException |
- | |
72 | * @throws JSONException |
69 | * @throws JSONException |
73 | * @throws AccessDeniedException |
70 | * @throws AccessDeniedException |
74 | */ |
71 | */ |
75 | public JSONArray openRepositoryCollection(1.5.0/docs/api/java/lang/Long.html">Long collectionId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
72 | public JSONArray openRepositoryCollection(1.5.0/docs/api/java/lang/Long.html">Long collectionId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
76 | 73 | ||
77 | boolean onlyVisible = !(userSession.getUser() != null && |
74 | boolean onlyVisible = !(userSession.getUser() != null && |
78 | (userSession.getUser().hasRole(REPOSITORY_DOCS_ROLE) |
75 | (userSession.getUser().hasRole(REPOSITORY_DOCS_ROLE) |
79 | || |
76 | || |
80 | userSession.getUser().isSuperuserOrAdmin())); |
77 | userSession.getUser().isSuperuserOrAdmin())); |
Line 90... | Line 87... | ||
90 | return RepositoryDocumentCollectionImpl.toJsonArray(childs); |
87 | return RepositoryDocumentCollectionImpl.toJsonArray(childs); |
91 | } |
88 | } |
92 | } |
89 | } |
93 | 90 | ||
94 | 91 | ||
95 | public JSONArray openRepositoryCollectionDocuments(1.5.0/docs/api/java/lang/Long.html">Long collectionId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
92 | public JSONArray openRepositoryCollectionDocuments(1.5.0/docs/api/java/lang/Long.html">Long collectionId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
96 | 93 | ||
97 | boolean onlyVisible = !(userSession.getUser() != null && |
94 | boolean onlyVisible = !(userSession.getUser() != null && |
98 | (userSession.getUser().hasRole(REPOSITORY_DOCS_ROLE) |
95 | (userSession.getUser().hasRole(REPOSITORY_DOCS_ROLE) |
99 | || |
96 | || |
100 | userSession.getUser().isSuperuserOrAdmin())); |
97 | userSession.getUser().isSuperuserOrAdmin())); |
101 | 98 | ||
102 | List<RepositoryDocumentImpl> docs = DaoFactory.getRepositoryDocumentDaoImpl().findDocumentsSortPublishDateDesc(onlyVisible, collectionId); |
99 | List<RepositoryDocumentImpl> docs = DaoFactory.getRepositoryDocumentDaoImpl().findDocumentsSortPublishDateDesc(onlyVisible, collectionId); |
103 | return RepositoryDocumentImpl.toJsonArray(docs); |
100 | return RepositoryDocumentImpl.toJsonArray(docs); |
104 | } |
101 | } |
105 | 102 | ||
106 | public JSONObject addRepositoryCollection(1.5.0/docs/api/java/lang/Long.html">Long collectionParentId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
103 | public JSONObject addRepositoryCollection(1.5.0/docs/api/java/lang/Long.html">Long collectionParentId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
107 | RepositoryDocumentCollectionImpl collectionParent = null; |
104 | RepositoryDocumentCollectionImpl collectionParent = null; |
108 | if(collectionParentId != null) |
105 | if(collectionParentId != null) |
109 | { |
106 | { |
110 | collectionParent = (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionParentId); |
107 | collectionParent = (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionParentId); |
111 | } |
108 | } |
Line 118... | Line 115... | ||
118 | collectionChild.setVisible(true); |
115 | collectionChild.setVisible(true); |
119 | DaoFactory.getRepositoryDocumentCollectionDaoImpl().save(collectionChild); |
116 | DaoFactory.getRepositoryDocumentCollectionDaoImpl().save(collectionChild); |
120 | return collectionChild.toJsonObject(); |
117 | return collectionChild.toJsonObject(); |
121 | } |
118 | } |
122 | 119 | ||
123 | public JSONObject changeParentRepositoryDocumentCollection(1.5.0/docs/api/java/lang/Long.html">Long collectionId,1.5.0/docs/api/java/lang/Long.html">Long newParentId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
120 | public JSONObject changeParentRepositoryDocumentCollection(1.5.0/docs/api/java/lang/Long.html">Long collectionId,1.5.0/docs/api/java/lang/Long.html">Long newParentId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
124 | RepositoryDocumentCollectionImpl collectionChild = (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionId); |
121 | RepositoryDocumentCollectionImpl collectionChild = (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionId); |
125 | RepositoryDocumentCollectionImpl collectionNewParent = newParentId == null ? null : (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(newParentId); |
122 | RepositoryDocumentCollectionImpl collectionNewParent = newParentId == null ? null : (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(newParentId); |
126 | 123 | ||
127 | if(collectionChild.getParent() != null) |
124 | if(collectionChild.getParent() != null) |
128 | { |
125 | { |
Line 138... | Line 135... | ||
138 | return collectionChild.toJsonObject(); |
135 | return collectionChild.toJsonObject(); |
139 | } |
136 | } |
140 | 137 | ||
141 | 138 | ||
142 | 139 | ||
143 | public JSONObject updateRepositoryCollection(1.5.0/docs/api/java/lang/String.html">String collection, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
140 | public JSONObject updateRepositoryCollection(1.5.0/docs/api/java/lang/String.html">String collection, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
144 | 141 | ||
145 | RepositoryDocumentCollectionImpl collectionChild = RepositoryDocumentCollectionImpl.loadFromJson(collection); |
142 | RepositoryDocumentCollectionImpl collectionChild = RepositoryDocumentCollectionImpl.loadFromJson(collection); |
146 | 143 | ||
147 | 144 | ||
148 | RepositoryDocumentCollectionImpl persistent = (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionChild.getId()); |
145 | RepositoryDocumentCollectionImpl persistent = (RepositoryDocumentCollectionImpl) DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionChild.getId()); |
Line 153... | Line 150... | ||
153 | persistent.setVisible(collectionChild.isVisible()); |
150 | persistent.setVisible(collectionChild.isVisible()); |
154 | 151 | ||
155 | return persistent.toJsonObject(); |
152 | return persistent.toJsonObject(); |
156 | } |
153 | } |
157 | 154 | ||
158 | public void deleteCollection(long collectionId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException, NotAuthorizedException |
155 | public void deleteCollection(long collectionId, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException, NotAuthorizedException |
159 | { |
156 | { |
160 | RepositoryDocumentCollection collection = DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionId); |
157 | RepositoryDocumentCollection collection = DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collectionId); |
161 | if(collection.getChilds().size() > 0) |
158 | if(collection.getChilds().size() > 0) |
162 | { |
159 | { |
163 | throw new NotAuthorizedException("A colecção " + collection.getName() + " não está vazia, tem colecções, limpe a colecção"); |
160 | throw new NotAuthorizedException("A colecção " + collection.getName() + " não está vazia, tem colecções, limpe a colecção"); |
Line 169... | Line 166... | ||
169 | } |
166 | } |
170 | DaoFactory.getRepositoryDocumentCollectionDaoImpl().delete(collection); |
167 | DaoFactory.getRepositoryDocumentCollectionDaoImpl().delete(collection); |
171 | } |
168 | } |
172 | 169 | ||
173 | 170 | ||
174 | public JSONArray checkRepositoryDocumentExistence(1.5.0/docs/api/java/lang/String.html">String docJson, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException, NotAuthorizedException |
171 | public JSONArray checkRepositoryDocumentExistence(1.5.0/docs/api/java/lang/String.html">String docJson, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException, NotAuthorizedException |
175 | { |
172 | { |
176 | JSONArray found = new JSONArray(); |
173 | JSONArray found = new JSONArray(); |
177 | RepositoryDocumentImpl view = RepositoryDocumentImpl.loadFromJson(docJson); |
174 | RepositoryDocumentImpl view = RepositoryDocumentImpl.loadFromJson(docJson); |
178 | List<RepositoryDocumentImpl> documents = DaoFactory.getRepositoryDocumentDaoImpl().findDocumentsByTitle(view.getTitle()); |
175 | List<RepositoryDocumentImpl> documents = DaoFactory.getRepositoryDocumentDaoImpl().findDocumentsByTitle(view.getTitle()); |
179 | if(documents.size() > 0) |
176 | if(documents.size() > 0) |
Line 184... | Line 181... | ||
184 | } |
181 | } |
185 | } |
182 | } |
186 | return found; |
183 | return found; |
187 | } |
184 | } |
188 | 185 | ||
189 | public JSONObject saveRepositoryDocument(1.5.0/docs/api/java/lang/String.html">String docJson, FilesUploadResult uploadedFiles, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException, NotAuthorizedException, ServiceException { |
186 | public JSONObject saveRepositoryDocument(1.5.0/docs/api/java/lang/String.html">String docJson, FilesUploadResult uploadedFiles, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException, NotAuthorizedException, ServiceException { |
190 | 187 | ||
191 | RepositoryDocumentImpl view = RepositoryDocumentImpl.loadFromJson(docJson); |
188 | RepositoryDocumentImpl view = RepositoryDocumentImpl.loadFromJson(docJson); |
192 | 189 | ||
193 | if(view.getCollection() == null || view.getCollection().getId() <= 0) |
190 | if(view.getCollection() == null || view.getCollection().getId() <= 0) |
194 | { |
191 | { |
Line 366... | Line 363... | ||
366 | history = history + line; |
363 | history = history + line; |
367 | persistent.setHistoryEdit(history); |
364 | persistent.setHistoryEdit(history); |
368 | } |
365 | } |
369 | 366 | ||
370 | 367 | ||
371 | public JSONArray loadCollectionsOrderedAsTree() throws JSONException, TransformationException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
368 | public JSONArray loadCollectionsOrderedAsTree() throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
372 | ArrayList<RepositoryDocumentCollectionImpl> collections = new ArrayList<RepositoryDocumentCollectionImpl>(); |
369 | ArrayList<RepositoryDocumentCollectionImpl> collections = new ArrayList<RepositoryDocumentCollectionImpl>(); |
373 | List<RepositoryDocumentCollection> collectionsRoots = DaoFactory.getRepositoryDocumentCollectionDaoImpl().findRoots(); |
370 | List<RepositoryDocumentCollection> collectionsRoots = DaoFactory.getRepositoryDocumentCollectionDaoImpl().findRoots(); |
374 | for(RepositoryDocumentCollection col : collectionsRoots) |
371 | for(RepositoryDocumentCollection col : collectionsRoots) |
375 | { |
372 | { |
376 | col.getName(); |
373 | col.getName(); |
Line 393... | Line 390... | ||
393 | } |
390 | } |
394 | 391 | ||
395 | 392 | ||
396 | 393 | ||
397 | 394 | ||
398 | public JSONObject addRepositoryInterface(UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
395 | public JSONObject addRepositoryInterface(UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
399 | RepositoryDocumentInterfaceImpl repositoryDocumentInterface = DomainObjectFactory.createRepositoryDocumentInterfaceImpl(); |
396 | RepositoryDocumentInterfaceImpl repositoryDocumentInterface = DomainObjectFactory.createRepositoryDocumentInterfaceImpl(); |
400 | repositoryDocumentInterface.setVisible(false); |
397 | repositoryDocumentInterface.setVisible(false); |
401 | DaoFactory.getRepositoryDocumentInterfaceDaoImpl().save(repositoryDocumentInterface); |
398 | DaoFactory.getRepositoryDocumentInterfaceDaoImpl().save(repositoryDocumentInterface); |
402 | return repositoryDocumentInterface.toJsonObject(); |
399 | return repositoryDocumentInterface.toJsonObject(); |
403 | } |
400 | } |
404 | public JSONObject updateRepositoryInterface(1.5.0/docs/api/java/lang/String.html">String jsonObject,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
401 | public JSONObject updateRepositoryInterface(1.5.0/docs/api/java/lang/String.html">String jsonObject,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
405 | 402 | ||
406 | RepositoryDocumentInterfaceImpl repositoryDocumentInterface = |
403 | RepositoryDocumentInterfaceImpl repositoryDocumentInterface = |
407 | RepositoryDocumentInterfaceImpl.loadFromJson(jsonObject); |
404 | RepositoryDocumentInterfaceImpl.loadFromJson(jsonObject); |
408 | 405 | ||
409 | RepositoryDocumentInterfaceImpl persistent = (RepositoryDocumentInterfaceImpl) DaoFactory.getRepositoryDocumentInterfaceDaoImpl().get(repositoryDocumentInterface.getId()); |
406 | RepositoryDocumentInterfaceImpl persistent = (RepositoryDocumentInterfaceImpl) DaoFactory.getRepositoryDocumentInterfaceDaoImpl().get(repositoryDocumentInterface.getId()); |
Line 412... | Line 409... | ||
412 | persistent.setSlug(repositoryDocumentInterface.getSlug()); |
409 | persistent.setSlug(repositoryDocumentInterface.getSlug()); |
413 | 410 | ||
414 | return persistent.toJsonObject(); |
411 | return persistent.toJsonObject(); |
415 | } |
412 | } |
416 | 413 | ||
417 | public void removeRepositoryInterface(1.5.0/docs/api/java/lang/Long.html">Long id,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException { |
414 | public void removeRepositoryInterface(1.5.0/docs/api/java/lang/Long.html">Long id,UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException { |
418 | 415 | ||
419 | RepositoryDocumentInterfaceImpl persistent = (RepositoryDocumentInterfaceImpl) DaoFactory.getRepositoryDocumentInterfaceDaoImpl().get(id); |
416 | RepositoryDocumentInterfaceImpl persistent = (RepositoryDocumentInterfaceImpl) DaoFactory.getRepositoryDocumentInterfaceDaoImpl().get(id); |
420 | DaoFactory.getRepositoryDocumentInterfaceDaoImpl().delete(persistent); |
417 | DaoFactory.getRepositoryDocumentInterfaceDaoImpl().delete(persistent); |
421 | } |
418 | } |
422 | 419 | ||
423 | public void saveRepositoryInterfaceData(1.5.0/docs/api/java/lang/Long.html">Long id,1.5.0/docs/api/java/lang/String.html">String dataJson, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException, AccessDeniedException, ServiceException { |
420 | public void saveRepositoryInterfaceData(1.5.0/docs/api/java/lang/Long.html">Long id,1.5.0/docs/api/java/lang/String.html">String dataJson, UserSession userSession) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, AccessDeniedException, ServiceException { |
424 | 421 | ||
425 | RepositoryInterface repositoryInterface = RepositoryInterface.loadFromJson(dataJson); |
422 | RepositoryInterface repositoryInterface = RepositoryInterface.loadFromJson(dataJson); |
426 | for(InterfaceRow row: repositoryInterface.getRows()) |
423 | for(InterfaceRow row: repositoryInterface.getRows()) |
427 | { |
424 | { |
428 | for(InterfaceColumn col : row.getColumns()) |
425 | for(InterfaceColumn col : row.getColumns()) |
Line 458... | Line 455... | ||
458 | break; |
455 | break; |
459 | } |
456 | } |
460 | } |
457 | } |
461 | } |
458 | } |
462 | 459 | ||
463 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws TransformationException, JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException |
460 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException |
464 | { |
461 | { |
465 | AbstractDao.getCurrentSession().beginTransaction(); |
462 | AbstractDao.getCurrentSession().beginTransaction(); |
466 | JSONArray array = new RepositoryDocumentService().loadCollectionsOrderedAsTree(); |
463 | JSONArray array = new RepositoryDocumentService().loadCollectionsOrderedAsTree(); |
467 | 1.5.0/docs/api/java/lang/System.html">System.out.println(array.toString()); |
464 | 1.5.0/docs/api/java/lang/System.html">System.out.println(array.toString()); |
468 | AbstractDao.getCurrentSession().getTransaction().commit(); |
465 | AbstractDao.getCurrentSession().getTransaction().commit(); |