- Timestamp:
- 08/01/14 16:03:43 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r1633 r1643 29 29 import org.eclipse.uml2.uml.Element; 30 30 import org.eclipse.uml2.uml.Interaction; 31 import org.eclipse.uml2.uml.InteractionFragment; 31 32 import org.eclipse.uml2.uml.Lifeline; 32 33 import org.eclipse.uml2.uml.Message; … … 42 43 import de.ugoe.cs.autoquest.eventcore.Event; 43 44 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 45 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 44 46 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 47 import de.ugoe.cs.autoquest.usageprofiles.TrieBasedModel; 45 48 46 49 /** … … 273 276 for (Event event : sequence) { 274 277 if (!(event.equals(Event.STARTEVENT) || event.equals(Event.ENDEVENT))) { 275 if (event.getType() instanceof SOAPEventType) { 276 SOAPEventType eventType = (SOAPEventType) event.getType(); 277 String serviceName = eventType.getServiceName(); 278 String methodName = eventType.getCalledMethod(); 279 Class targetClass = classMap.get(serviceName); 280 if (targetClass == null) { 281 throw new RuntimeException( 282 "Could not find class in the UML model that belong to the service: " + 283 serviceName); 284 } 285 286 Lifeline targetLifeline = interaction.getLifeline(serviceName); 287 if (targetLifeline == null) { 288 targetLifeline = interaction.createLifeline(serviceName); 289 Association association = 290 (Association) model.getPackagedElement("user_" + serviceName, true, 291 UMLPackage.Literals.ASSOCIATION, 292 true); 293 targetLifeline.setRepresents(association.getMemberEnd(serviceName, classMap 294 .get(serviceName))); 295 } 296 MessageOccurrenceSpecification sendFragment = 297 (MessageOccurrenceSpecification) interaction 298 .createFragment(i + ":" + methodName + "_sendFragment", 299 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 300 MessageOccurrenceSpecification recvFragment = 301 (MessageOccurrenceSpecification) interaction 302 .createFragment(i + ":" + methodName + "_recvFragment", 303 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 304 305 sendFragment.setCovered(userLifeline); 306 recvFragment.setCovered(targetLifeline); 307 308 Message message = interaction.createMessage(methodName); 309 message.setSignature(getOperationFromName(targetClass.getOperations(), 310 methodName)); 311 message.setSendEvent(sendFragment); 312 message.setReceiveEvent(recvFragment); 313 314 sendFragment.setMessage(message); 315 recvFragment.setMessage(message); 316 } 317 else { 278 String serviceName = getServiceNameFromEvent(event); 279 String methodName = getCalledMethodFromEvent(event); 280 281 Class targetClass = classMap.get(serviceName); 282 if (targetClass == null) { 318 283 throw new RuntimeException( 319 "Wrong event type. Only SOAPEventType supported but was: " + 320 event.getType().getClass().getName()); 321 } 284 "Could not find class in the UML model that belong to the service: " + 285 serviceName); 286 } 287 288 Lifeline targetLifeline = interaction.getLifeline(serviceName); 289 if (targetLifeline == null) { 290 targetLifeline = interaction.createLifeline(serviceName); 291 Association association = 292 (Association) model.getPackagedElement("user_" + serviceName, true, 293 UMLPackage.Literals.ASSOCIATION, 294 true); 295 targetLifeline 296 .setRepresents(association.getMemberEnd(serviceName, 297 classMap.get(serviceName))); 298 } 299 MessageOccurrenceSpecification sendFragment = 300 (MessageOccurrenceSpecification) interaction 301 .createFragment(i + ":" + methodName + "_sendFragment", 302 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 303 MessageOccurrenceSpecification recvFragment = 304 (MessageOccurrenceSpecification) interaction 305 .createFragment(i + ":" + methodName + "_recvFragment", 306 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 307 308 sendFragment.setCovered(userLifeline); 309 recvFragment.setCovered(targetLifeline); 310 311 Message message = interaction.createMessage(methodName); 312 message.setSignature(getOperationFromName(targetClass.getOperations(), methodName)); 313 message.setSendEvent(sendFragment); 314 message.setReceiveEvent(recvFragment); 315 316 sendFragment.setMessage(message); 317 recvFragment.setMessage(message); 318 322 319 i++; 323 320 } 321 } 322 } 323 324 /** 325 * <p> 326 * Calculates the usage score of an interaction as the logsum of the event probabilities 327 * multiplied with the length of the interaction. 328 * </p> 329 * 330 * @param interaction 331 * interaction for which the score is calculated 332 * @param usageProfile 333 * usage profile used for the calculation 334 * @return calculated usage score 335 */ 336 public static double calculateUsageScore(Interaction interaction, TrieBasedModel usageProfile) { 337 double usageScore = 0.0d; 338 339 EList<InteractionFragment> interactionFragments = interaction.getFragments(); 340 List<Event> eventSequence = new LinkedList<>(); 341 eventSequence.add(Event.STARTEVENT); 342 for (InteractionFragment interactionFragment : interactionFragments) { 343 if (interactionFragment.getName() != null && 344 interactionFragment.getName().endsWith("_recvFragment")) 345 { 346 String serviceName = 347 interactionFragment.getCovereds().get(0).getRepresents().getName(); 348 String methodName = "UNKNOWN"; 349 if (interactionFragment instanceof MessageOccurrenceSpecification) { 350 methodName = 351 ((MessageOccurrenceSpecification) interactionFragment).getMessage() 352 .getName(); 353 } 354 eventSequence.add(new Event(new SimpleSOAPEventType(methodName, serviceName))); 355 } 356 } 357 double prob = usageProfile.getLogSum(eventSequence); 358 usageScore = prob * eventSequence.size(); 359 360 return usageScore; 361 } 362 363 /** 364 * <p> 365 * Helper function to get the name of a service from a SOAP event. 366 * </p> 367 * 368 * @param event 369 * event for which the service name is retrieved 370 * @return service name 371 */ 372 private static String getServiceNameFromEvent(Event event) { 373 if (event.getType() instanceof SOAPEventType) { 374 return ((SOAPEventType) event.getType()).getServiceName(); 375 } 376 else if (event.getType() instanceof SimpleSOAPEventType) { 377 return ((SimpleSOAPEventType) event.getType()).getServiceName(); 378 } 379 else { 380 throw new RuntimeException( 381 "Wrong event type. Only SOAPEventType and SimpleSOAPEventType supported but was: " + 382 event.getType().getClass().getName()); 383 } 384 } 385 386 /** 387 * 388 * <p> 389 * Helper function to get the called method from a SOAP event 390 * </p> 391 * 392 * @param event 393 * event for which the called method is retrieved 394 * @return called method 395 */ 396 private static String getCalledMethodFromEvent(Event event) { 397 if (event.getType() instanceof SOAPEventType) { 398 return ((SOAPEventType) event.getType()).getCalledMethod(); 399 } 400 else if (event.getType() instanceof SimpleSOAPEventType) { 401 return ((SimpleSOAPEventType) event.getType()).getCalledMethod(); 402 } 403 else { 404 throw new RuntimeException( 405 "Wrong event type. Only SOAPEventType and SimpleSOAPEventType supported but was: " + 406 event.getType().getClass().getName()); 324 407 } 325 408 }
Note: See TracChangeset
for help on using the changeset viewer.