Changeset 19632
- Timestamp:
- 02/02/12 19:37:10 (4 months ago)
- Location:
- trunk/Jav_Wsp/src/eu/scenari/wsp/service/comment
- Files:
-
- 5 edited
-
CommentAction.java (modified) (3 diffs)
-
CommentActionsStack.java (modified) (5 diffs)
-
CommentThread.java (modified) (3 diffs)
-
OriPath.java (modified) (1 diff)
-
SvcCommentDialog.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Jav_Wsp/src/eu/scenari/wsp/service/comment/CommentAction.java
r19527 r19632 49 49 public static final int sUPDATE = 3; 50 50 51 public static final int sRESPOND = 4; 52 51 53 protected int fAction; 52 54 … … 55 57 protected long fTimeStamp; 56 58 59 protected CommentThread fCommentThread; 60 57 61 public CommentAction() { 58 62 fTimeStamp = -1; 59 63 } 60 64 61 public CommentAction(int pAction, OriPath pOripath, long pTimeStamp ) {65 public CommentAction(int pAction, OriPath pOripath, long pTimeStamp, CommentThread pCommentThread) { 62 66 this.fAction = pAction; 63 67 this.fOripath = pOripath; 64 68 this.fTimeStamp = pTimeStamp; 69 this.fCommentThread = pCommentThread; 65 70 } 66 71 … … 89 94 } 90 95 96 public CommentThread getCommentThread() { 97 return fCommentThread; 98 } 99 100 public void setCommentThread(CommentThread pCommentThread) { 101 fCommentThread = pCommentThread; 102 } 103 91 104 } -
trunk/Jav_Wsp/src/eu/scenari/wsp/service/comment/CommentActionsStack.java
r19527 r19632 82 82 if (!vKnownTimeStamp) { 83 83 fTable.put(vId, new ArrayList<CommentAction>()); 84 fTable.get(vId).add(new CommentAction(CommentAction.sINIT, null, vSrcNode.getLastModif() ));84 fTable.get(vId).add(new CommentAction(CommentAction.sINIT, null, vSrcNode.getLastModif(), null)); 85 85 } 86 86 } … … 88 88 else { 89 89 fTable.put(vId, new ArrayList<CommentAction>()); 90 fTable.get(vId).add(new CommentAction(CommentAction.sINIT, null, vSrcNode.getLastModif() ));90 fTable.get(vId).add(new CommentAction(CommentAction.sINIT, null, vSrcNode.getLastModif(), null)); 91 91 } 92 92 } … … 105 105 if (vCommentAction.getAction() == CommentAction.sINIT) { 106 106 return false; 107 } else {107 } else if (pOripath != null) { 108 108 vSuccess = pOripath.updatePath(vCommentAction.getAction(), vCommentAction.fOripath); 109 109 } … … 111 111 } 112 112 return vSuccess; 113 } 114 115 public boolean checkTimeStamp(long pRequestTimeStamp, String pRefUri) { 116 for (CommentAction vCommentAction : fTable.get(pRefUri)) { 117 if (pRequestTimeStamp < vCommentAction.getTimeStamp()) { 118 if (vCommentAction.getAction() == CommentAction.sINIT) return false; 119 } 120 } 121 return true; 113 122 } 114 123 … … 125 134 } 126 135 136 public List<CommentAction> getCommentActionSinceTimeStamp(String pId, long pTimeStamp) throws Exception { 137 138 List<CommentAction> vResult = new ArrayList<CommentAction>(); 139 if (fTable.containsKey(pId)) { 140 for (CommentAction vCommentAction : fTable.get(pId)) { 141 if (vCommentAction.getTimeStamp() > pTimeStamp) vResult.add(vCommentAction); 142 } 143 } 144 return vResult; 145 } 146 127 147 } -
trunk/Jav_Wsp/src/eu/scenari/wsp/service/comment/CommentThread.java
r19527 r19632 51 51 protected boolean fChecked; 52 52 53 protected char fStatut; 54 55 public static char sSTATUT_LISTE = '='; 56 57 public static char sSTATUT_ADD = '+'; 58 59 public static char sSTATUT_REMOVE = '-'; 60 61 public static char sSTATUT_UPDATE = '~'; 62 53 63 public CommentThread() { 54 64 super(); 65 fStatut = sSTATUT_LISTE; 55 66 } 56 67 … … 79 90 public void toJson(JsonSerializer pJson) throws Exception { 80 91 pJson.startObject(); 92 pJson.key("sync"); 93 pJson.val(fStatut); 81 94 pJson.key("oriPath"); 82 95 pJson.valString(fOriPath); 83 96 pJson.key("threadClosed"); 84 97 pJson.valBoolean(fChecked); 98 85 99 pJson.key("comments"); 86 100 pJson.startArray(); … … 101 115 } 102 116 117 public void setStatut(char pStatut) { 118 fStatut = pStatut; 119 } 120 103 121 }; -
trunk/Jav_Wsp/src/eu/scenari/wsp/service/comment/OriPath.java
r19527 r19632 142 142 143 143 boolean vSuccess = true; 144 boolean vSameSize; 145 146 if (fRelativePath.length == pOriPath.getRelativePath().length) 147 vSameSize = true; 148 else vSameSize = false; 149 int vMax = Math.min(fRelativePath.length, pOriPath.getRelativePath().length); 150 for (int i = 0; i < vMax; i++) { 151 //mark as changed at the first difference only !!! 152 if (pOriPath.getRelativePath()[i] != fRelativePath[i]) { 153 if (pOriPath.getRelativePath()[i] < fRelativePath[i]) switch (pAction) { 154 case CommentAction.sCREATE: 155 fRelativePath[i]++; 156 break; 157 case CommentAction.sDELETE: 158 fRelativePath[i]--; 159 break; 160 } 161 break; 162 } 163 //If same relative Path and an action on the full comment 164 if (i + 1 == vMax && vSameSize && pOriPath.getRelativeCommentOrder() == sNO_RELATIVE_COMMENT_ORDER) { 165 switch (pAction) { 166 case CommentAction.sCREATE: 167 fRelativePath[i]++; 168 break; 169 //THIS COMMENT WAS UNFORTUNATELY REMOVED 170 case CommentAction.sDELETE: 171 vSuccess = false; 172 break; 173 174 case CommentAction.sUPDATE: 175 vSuccess = false; 176 break; 177 } 178 } 179 //if same relative path and an action on a comment in the thread 180 else if (i + 1 == vMax && vSameSize) { 181 if (pOriPath.getRelativeCommentOrder() < fRelativeCommentOrder) { 144 145 if (fRelativePath.length >= pOriPath.getRelativePath().length) { 146 for (int i = 0; i < pOriPath.getRelativePath().length; i++) { 147 //case the Action was on an other branch 148 if (i != pOriPath.getRelativePath().length - 1 && fRelativePath[i] != pOriPath.getRelativePath()[i]) break; 149 //Case the action wes on an uncle/brother ... 150 if (i == pOriPath.getRelativePath().length - 1 && fRelativePath[i] > pOriPath.getRelativePath()[i] && pOriPath.getRelativeCommentOrder() == sNO_RELATIVE_COMMENT_ORDER) { 182 151 switch (pAction) { 183 152 case CommentAction.sCREATE: 184 fRelative CommentOrder++;153 fRelativePath[i]++; 185 154 break; 186 187 155 case CommentAction.sDELETE: 188 fRelativeCommentOrder--; 189 break; 190 } 191 } else if (pOriPath.getRelativeCommentOrder() == fRelativeCommentOrder) { 192 switch (pAction) { 193 case CommentAction.sCREATE: 194 fRelativeCommentOrder++; 195 break; 196 //THIS COMMENT WAS UNFORTUNATELY REMOVED 197 case CommentAction.sDELETE: 198 vSuccess = false; 199 break; 200 201 case CommentAction.sUPDATE: 202 vSuccess = false; 156 fRelativePath[i]--; 203 157 break; 204 158 } 205 159 } 206 } 207 //other cases, errors ! (a relative pass point a sub comment part of a comment 208 else if (i + 1 == vMax) { 209 vSuccess = false; 160 //Case the action was on the same node 161 if (i == pOriPath.getRelativePath().length - 1 && fRelativePath[i] == pOriPath.getRelativePath()[i]) { 162 if (pOriPath.getRelativeCommentOrder() == sNO_RELATIVE_COMMENT_ORDER) { 163 switch (pAction) { 164 case CommentAction.sCREATE: 165 fRelativePath[i]++; 166 break; 167 //THIS COMMENT WAS UNFORTUNATELY REMOVED 168 case CommentAction.sDELETE: 169 vSuccess = false; 170 break; 171 172 case CommentAction.sUPDATE: 173 vSuccess = false; 174 break; 175 } 176 } else { 177 if (pOriPath.getRelativeCommentOrder() < fRelativeCommentOrder) { 178 switch (pAction) { 179 case CommentAction.sCREATE: 180 fRelativeCommentOrder++; 181 break; 182 183 case CommentAction.sDELETE: 184 fRelativeCommentOrder--; 185 break; 186 } 187 } else if (pOriPath.getRelativeCommentOrder() == fRelativeCommentOrder) { 188 switch (pAction) { 189 case CommentAction.sCREATE: 190 fRelativeCommentOrder++; 191 break; 192 //THIS COMMENT WAS UNFORTUNATELY REMOVED 193 case CommentAction.sDELETE: 194 vSuccess = false; 195 break; 196 197 case CommentAction.sUPDATE: 198 vSuccess = false; 199 break; 200 } 201 } 202 } 203 } 210 204 } 211 205 } -
trunk/Jav_Wsp/src/eu/scenari/wsp/service/comment/SvcCommentDialog.java
r19527 r19632 87 87 88 88 /** 89 * CDACTION_SYNC : Envoie toutes les modifications dans les commentaires depuis TimeStamp. 90 * 91 * Param par défaut : Code de l'atelier. 92 * refUris : liste de srcUri ou srcId de la source pour laquelle obtenir les commentaires. 93 * TimeStamp : timestamp à partir duquel envoyer les dernières modifications dans les commentaires 94 */ 95 public static final String CDACTION_SYNC = "Sync"; 96 97 /** 89 98 * CDACTION_CREATE : creation d'un nouveau thread de commentaires 90 99 * … … 160 169 public SvcCommentDialog(IService pService, CommentActionsStack pCommentActionsStack) { 161 170 super(pService); 162 fComments = new HashMap<String, List<CommentThread>>();163 171 fLastActionsTable = pCommentActionsStack; 164 172 } … … 193 201 fOripathWrapper.insertComment(vCommentThread.toXml()); 194 202 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 195 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sCREATE, fOripath, fSrcNodes.get(0).getLastModif() ));196 197 list Comments(fSrcNodes);203 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sCREATE, fOripath, fSrcNodes.get(0).getLastModif(), vCommentThread)); 204 205 listNewComments(fSrcNodes); 198 206 } else { 199 207 listComments(fSrcNodes); … … 211 219 findSrcs(); 212 220 fLastActionsTable.updateTableFromSrc(fSrcNodes); 221 CommentThread vThread; 213 222 if (fLastActionsTable.trackOripathEvolutions(fParamTimeStamp, fOripath)) { 214 if (fOripath.getRelativeCommentOrder() == -1) {223 if (fOripath.getRelativeCommentOrder() == OriPath.sNO_RELATIVE_COMMENT_ORDER) { 215 224 ScComment vComment = new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText); 216 CommentThreadvThread = new CommentThread(fOripath.toString());225 vThread = new CommentThread(fOripath.toString()); 217 226 vThread.add(vComment); 218 227 fOripathWrapper.updateComment(vThread.toXml()); … … 222 231 List<CommentThread> vThreads = new ArrayList<CommentThread>(); 223 232 vThreads = recursiveCommentsSearch(fOripathWrapper.getComment(), vThreads, fOripath.getRelativePathAsString()); 224 //Sub case 1 comment exists in thread 225 if (vThreads.size() == 1 && vThreads.get(0).size() > fOripath.getRelativeCommentOrder()) { 226 vThreads.get(0).set(fOripath.getRelativeCommentOrder(), new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText)); 227 fOripathWrapper.updateComment(vThreads.get(0).toXml()); 228 }//Sub case 2 comments doesn't exists (ex : requested an update of the second comment but thread contains only one comment) 229 //add a new comment in the thread 230 else if (vThreads.size() == 1) { 231 vThreads.get(0).add(new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText)); 232 fOripathWrapper.updateComment(vThreads.get(0).toXml()); 233 if (vThreads.size() == 1) { 234 vThread = vThreads.get(0); 235 //Sub case 1 comment exists in thread 236 if (vThread.size() > fOripath.getRelativeCommentOrder()) { 237 vThread.set(fOripath.getRelativeCommentOrder(), new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText)); 238 fOripathWrapper.updateComment(vThread.toXml()); 239 }//Sub case 2 comments doesn't exists (ex : requested an update of the second comment but thread contains only one comment) 240 //add a new comment in the thread 241 else { 242 vThread.add(new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText)); 243 fOripathWrapper.updateComment(vThread.toXml()); 244 } 233 245 } else throw new Exception("This originpath doesn't point a SCENARI comment but a standard XML comment. Unable to update"); 234 246 } 235 236 listComments(fSrcNodes);237 247 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 238 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sUPDATE, fOripath, fSrcNodes.get(0).getLastModif() ));239 list Comments(fSrcNodes);248 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sUPDATE, fOripath, fSrcNodes.get(0).getLastModif(), vThread)); 249 listNewComments(fSrcNodes); 240 250 } else { 241 251 listComments(fSrcNodes); … … 257 267 List<CommentThread> vThreads = new ArrayList<CommentThread>(); 258 268 vThreads = recursiveCommentsSearch(fOripathWrapper.getComment(), vThreads, fOripath.getRelativePathAsString()); 269 CommentThread vThread; 259 270 if (vThreads.size() == 1) { 260 vThreads.get(0).add(new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText)); 261 fOripathWrapper.updateComment(vThreads.get(0).toXml()); 271 vThread = vThreads.get(0); 272 vThread.add(new ScComment(getContextUser().getAccount(), String.valueOf(System.currentTimeMillis()), fParamText)); 273 fOripathWrapper.updateComment(vThread.toXml()); 262 274 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 263 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sCREATE, fOripath, fSrcNodes.get(0).getLastModif() ));275 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sCREATE, fOripath, fSrcNodes.get(0).getLastModif(), vThread)); 264 276 } else { 265 277 throw new Exception("This originpath doesn't point a SCENARI comment but a standard XML comment. Unable to respond"); 266 278 } 267 list Comments(fSrcNodes);279 listNewComments(fSrcNodes); 268 280 269 281 } else { … … 286 298 fLastActionsTable.updateTableFromSrc(fSrcNodes); 287 299 if (fLastActionsTable.trackOripathEvolutions(fParamTimeStamp, fOripath)) { 288 if (fOripath.getRelativeCommentOrder() == -1) { 300 List<CommentThread> vThreads = new ArrayList<CommentThread>(); 301 vThreads = recursiveCommentsSearch(fOripathWrapper.getComment(), vThreads, fOripath.getRelativePathAsString()); 302 CommentThread vThread = vThreads.get(0); 303 304 if (fOripath.getRelativeCommentOrder() == OriPath.sNO_RELATIVE_COMMENT_ORDER) { 289 305 fOripathWrapper.removeNode(); 290 306 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 291 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif() ));307 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif(), vThread)); 292 308 293 309 } 294 310 //Case oripath form is refUri#relativePath#commentNumberInThread 295 311 else { 296 List<CommentThread> vThreads = new ArrayList<CommentThread>();297 vThreads = recursiveCommentsSearch(fOripathWrapper.getComment(), vThreads, fOripath.getRelativePathAsString());298 312 // case everythings is fine 299 313 if (vThreads.size() == 1 && vThreads.get(0).size() > fOripath.getRelativeCommentOrder()) { … … 304 318 fOripathWrapper.removeNode(); 305 319 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 306 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif())); 320 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif(), vThread)); 321 listNewComments(fSrcNodes); 307 322 308 323 } … … 313 328 fOripathWrapper.updateComment(vThreads.get(0).toXml()); 314 329 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 315 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif() ));316 330 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif(), vThread)); 331 listNewComments(fSrcNodes); 317 332 } 318 333 //case the thread have no comments … … 322 337 fOripath.setRelativeCommentOrder(OriPath.sNO_RELATIVE_COMMENT_ORDER); 323 338 writeDom(fOripathWrapper.getDocument(), fSrcNodes.get(0)); 324 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif() ));325 339 fLastActionsTable.addCommentAction(fSrcNodes.get(0), new CommentAction(CommentAction.sDELETE, fOripath, fSrcNodes.get(0).getLastModif(), vThread)); 340 listNewComments(fSrcNodes); 326 341 //Case the node is not a thread or the comment index is out of boundary 327 342 } else { … … 339 354 } 340 355 341 listComments(fSrcNodes); 356 } else if (CDACTION_SYNC.equals(vCdAction)) { 357 findSrcs(); 358 boolean vSucess = true; 359 String vRefUri; 360 fLastActionsTable.updateTableFromSrc(fSrcNodes); 361 for (ISrcNode vSrcNode : fSrcNodes) { 362 vRefUri = SrcFeatureIds.getSrcId(vSrcNode); 363 if (vRefUri == null) { 364 vRefUri = SrcFeatureIds.getRefUri(vSrcNode); 365 } 366 vSucess = fLastActionsTable.checkTimeStamp(fParamTimeStamp, vRefUri); 367 if (!vSucess) break; 368 } 369 if (fSrcNodes != null && vSucess) { 370 listNewComments(fSrcNodes); 371 } else { 372 fSuccessfullRequest = false; 373 listComments(fSrcNodes); 374 } 375 342 376 } else { 343 377 vResult = super.xExecuteDialog(); … … 348 382 } 349 383 384 protected void listNewComments(List<ISrcNode> pSrcNodes) { 385 fComments = new HashMap<String, List<CommentThread>>(); 386 for (ISrcNode vSrcNode : pSrcNodes) { 387 try { 388 String vId = SrcFeatureIds.getSrcId(vSrcNode); 389 if (vId == null) vId = SrcFeatureIds.getRefUri(vSrcNode); 390 391 List<CommentAction> vCommentActions = fLastActionsTable.getCommentActionSinceTimeStamp(vId, fParamTimeStamp); 392 for (CommentAction vCommentAction : vCommentActions) { 393 394 switch (vCommentAction.fAction) { 395 case CommentAction.sCREATE: 396 //Case respond 397 if (vCommentAction.getOripath().getRelativeCommentOrder() != OriPath.sNO_RELATIVE_COMMENT_ORDER) { 398 vCommentAction.getCommentThread().setStatut(CommentThread.sSTATUT_UPDATE); 399 } 400 //Case true creation 401 else { 402 vCommentAction.getCommentThread().setStatut(CommentThread.sSTATUT_ADD); 403 } 404 break; 405 case CommentAction.sDELETE: 406 if (vCommentAction.getOripath().getRelativeCommentOrder() != OriPath.sNO_RELATIVE_COMMENT_ORDER) 407 vCommentAction.getCommentThread().setStatut(CommentThread.sSTATUT_UPDATE); 408 409 else vCommentAction.getCommentThread().setStatut(CommentThread.sSTATUT_REMOVE); 410 break; 411 case CommentAction.sUPDATE: 412 vCommentAction.getCommentThread().setStatut(CommentThread.sSTATUT_UPDATE); 413 break; 414 415 default: 416 vCommentAction.getCommentThread().setStatut(CommentThread.sSTATUT_LISTE); 417 break; 418 } 419 420 if (!fComments.containsKey(vId)) fComments.put(vId, new ArrayList<CommentThread>()); 421 fComments.get(vId).add(vCommentAction.getCommentThread()); 422 } 423 } catch (Exception e) { 424 LogMgr.addMessage(e, "Fail to find refUri : " + vSrcNode.getSrcUri()); 425 fError = LogMgr.getMessage(e); 426 } 427 } 428 429 } 430 350 431 protected void listComments(List<ISrcNode> pSrcNodes) { 432 fComments = new HashMap<String, List<CommentThread>>(); 351 433 for (ISrcNode vSrcNode : pSrcNodes) { 352 434 try {
Note: See TracChangeset
for help on using the changeset viewer.