Skip to content

Commit

Permalink
User Story to Subdomain transformation: solve string to ID problems
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-ka committed Aug 21, 2024
1 parent 98a3a62 commit 5260191
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.contextmapper.dsl.cml.XtextIdHelper;
import org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory;
import org.contextmapper.dsl.contextMappingDSL.Domain;
import org.contextmapper.dsl.contextMappingDSL.Feature;
Expand All @@ -45,6 +46,8 @@ public class DeriveSubdomainFromUserRequirements extends AbstractRefactoring imp
private Set<String> userRequiremendIds = Sets.newHashSet();
private String domainName;
private String subdomainName;

private XtextIdHelper idHelper = new XtextIdHelper();

public DeriveSubdomainFromUserRequirements(String domainName, String subdomainName, Set<String> userRequirements) {
this.domainName = domainName;
Expand Down Expand Up @@ -102,7 +105,7 @@ private void deriveSubdomainEntities4Features(Subdomain subdomain, String urName
String entityName = createEntityIfNotExisting(feature.getEntity(), subdomain, feature.getEntityAttributes());

// create the service
String serviceName = urName.substring(0, 1).toUpperCase() + urName.substring(1) + "Service";
String serviceName = idHelper.convertStringToXtextID(urName.substring(0, 1).toUpperCase() + urName.substring(1) + "Service");
Optional<Service> alreadyExistingService = subdomain.getServices().stream().filter(s -> serviceName.equals(s.getName())).findFirst();
Service service;
if (!alreadyExistingService.isPresent()) {
Expand All @@ -112,7 +115,7 @@ private void deriveSubdomainEntities4Features(Subdomain subdomain, String urName
service = alreadyExistingService.get();
}

String operationName = feature.getVerb().replace(" ", "_") + entityName;
String operationName = idHelper.convertStringToXtextID(feature.getVerb().replace(" ", "_") + entityName);
Optional<ServiceOperation> alreadyExistingServiceOperation = service.getOperations().stream().filter(o -> operationName.equals(o.getName())).findFirst();
if (!alreadyExistingServiceOperation.isPresent())
addElementToEList(service.getOperations(), createServiceOperation(operationName));
Expand Down Expand Up @@ -160,7 +163,7 @@ private String createEntityIfNotExisting(String entity, Subdomain subdomain, Lis
}

private String mapEntityName(String entityName) {
return entityName.trim().replace(" ", "_");
return idHelper.convertStringToXtextID(entityName.trim());
}

private void createEntityAttributes(Entity entity, List<String> attributeNames) {
Expand All @@ -183,7 +186,7 @@ private void createEntityAttributes(Entity entity, List<String> attributeNames)
private String encodeAttrName(String originalName) {
String name = originalName.trim();
name = name.substring(0, 1).toLowerCase() + name.substring(1);
return name;
return new XtextIdHelper().convertStringToXtextID(name);
}

private Service createService(String serviceName, String entityName, String verb) {
Expand Down

0 comments on commit 5260191

Please sign in to comment.