Search in sources :

Example 1 with Service

use of ch.hsr.servicecutter.api.model.Service in project context-mapper-dsl by ContextMapper.

the class ServiceCutterOutputToContextMappingModelConverter method reconstructReference.

private void reconstructReference(DomainObject sourceObject, Reference originalReference, String targetTypeName) {
    BoundedContext parentBC = new CMLModelObjectsResolvingHelper(originalModelState).resolveBoundedContext(sourceObject);
    if (parentBC == null)
        // in case this source object is not part of a Bounded Context
        return;
    List<DomainObject> targetDomainObjects = EcoreUtil2.eAllOfType(model, DomainObject.class).stream().filter(obj -> obj.getName().equals(targetTypeName)).collect(Collectors.toList());
    if (targetDomainObjects.size() == 1) {
        Reference reference = TacticdslFactory.eINSTANCE.createReference();
        reference.setName(originalReference.getName());
        reference.setDomainObjectType(targetDomainObjects.get(0));
        reference.setCollectionType(originalReference.getCollectionType());
        reference.setDoc(originalReference.getDoc());
        sourceObject.getReferences().add(reference);
    } else {
        sourceObject.setComment("/* Service Cut generator: it was not possible to reconstruct the reference '" + originalReference.getName() + "' from " + sourceObject.getName() + " to " + targetTypeName + ". Please re-create that reference manually. */");
    }
}
Also used : SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) URI(org.eclipse.emf.common.util.URI) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) HashSet(java.util.HashSet) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) UserRequirement(org.contextmapper.dsl.contextMappingDSL.UserRequirement) Lists(com.google.common.collect.Lists) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) ServiceRelation(ch.hsr.servicecutter.api.model.ServiceRelation) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Map(java.util.Map) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) SolverPriority(ch.hsr.servicecutter.solver.SolverPriority) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) Service(ch.hsr.servicecutter.api.model.Service) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) SharedKernel(org.contextmapper.dsl.contextMappingDSL.SharedKernel) SolverAlgorithm(ch.hsr.servicecutter.solver.SolverAlgorithm) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext)

Example 2 with Service

use of ch.hsr.servicecutter.api.model.Service in project context-mapper-dsl by ContextMapper.

the class ServiceCutterOutputToContextMappingModelConverter method convert.

public ContextMappingModel convert(SolverResult serviceCutterResult) {
    model = contextMappingFactory.createContextMappingModel();
    ContextMap contextMap = contextMappingFactory.createContextMap();
    if (originalModelState != null && originalModelState.getMap() != null) {
        contextMap.setName(originalModelState.getMap().getName());
        contextMap.setState(originalModelState.getMap().getState());
        contextMap.setType(originalModelState.getMap().getType());
    }
    for (Service service : serviceCutterResult.getServices()) {
        BoundedContext bc = createOrGetBoundedContext(service.getName());
        bc.setComment(generateBCComment(service));
        Aggregate aggregate = contextMappingFactory.createAggregate();
        aggregate.setName("Aggregate_" + service.getId());
        aggregate.getDomainObjects().addAll(convertEntities(service.getId(), service.getNanoentities()));
        bc.getAggregates().add(aggregate);
        model.getBoundedContexts().add(bc);
        contextMap.getBoundedContexts().add(bc);
    }
    contextMap.getRelationships().addAll(convertRelationships(serviceCutterResult.getRelations()));
    model.setMap(contextMap);
    reconstructReferencesIfPossible();
    copyRootElementsNotAffected();
    model.setTopComment(generateTopComment());
    return model;
}
Also used : Service(ch.hsr.servicecutter.api.model.Service) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap)

Aggregations

Service (ch.hsr.servicecutter.api.model.Service)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)2 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)2 ServiceCutterContext (ch.hsr.servicecutter.api.ServiceCutterContext)1 ServiceRelation (ch.hsr.servicecutter.api.model.ServiceRelation)1 SolverResult (ch.hsr.servicecutter.api.model.SolverResult)1 SolverAlgorithm (ch.hsr.servicecutter.solver.SolverAlgorithm)1 SolverConfiguration (ch.hsr.servicecutter.solver.SolverConfiguration)1 SolverPriority (ch.hsr.servicecutter.solver.SolverPriority)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1