Skip to content

Commit

Permalink
finish rest service templates, osgi templates started
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborflorian committed Oct 13, 2023
1 parent 9fa7159 commit 37ee397
Show file tree
Hide file tree
Showing 17 changed files with 1,228 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ public static String namedElementApiRestParentPath(NamedElement namedElement) {
return apiPackageName().replaceAll("\\.", "/" ) + REST + "/" + namedElementParentPath(namedElement);
}

public static String applicationClassName(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName()) + "ApplicationConfig" );
public static String applicationClassName(NamedElement namedElement) {
return StringUtils.capitalize(safeName(namedElement.getName()) + "ApplicationConfig" );
}

public static String className(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName()));
public static String className(NamedElement namedElement) {
return StringUtils.capitalize(safeName(namedElement.getName()));
}

public static String applicationFqName(TransferObjectType transferObjectType) {
return namedElementApiPackageName(transferObjectType) + "." + applicationClassName(transferObjectType);
public static String firstToLower(String input) {
return StringUtils.uncapitalize(safeName(input));
}

public static String applicationFqName(NamedElement namedElement) {
return namedElementApiPackageName(namedElement) + "." + applicationClassName(namedElement);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import hu.blackbelt.judo.meta.psm.derived.StaticNavigation;
import hu.blackbelt.judo.meta.psm.namespace.*;
import hu.blackbelt.judo.meta.psm.namespace.Package;
import hu.blackbelt.judo.meta.psm.service.TransferAttribute;
import hu.blackbelt.judo.meta.psm.service.TransferObjectRelation;
import hu.blackbelt.judo.meta.psm.service.TransferObjectType;
import hu.blackbelt.judo.meta.psm.service.TransferOperation;
Expand All @@ -38,8 +39,7 @@
import java.util.stream.Collectors;

import static com.github.jknack.handlebars.internal.lang3.StringUtils.capitalize;
import static hu.blackbelt.judo.psm.generator.jackson.api.ObjectTypeHelper.getEntity;
import static hu.blackbelt.judo.psm.generator.jackson.api.ObjectTypeHelper.isEntity;
import static hu.blackbelt.judo.psm.generator.jackson.api.ObjectTypeHelper.*;

@TemplateHelper
public class JavaNamespaceHelper extends StaticMethodValueResolver {
Expand Down Expand Up @@ -111,11 +111,11 @@ public static String safeNamedElementOriginalNameForClassNames(NamedElement name
}

public static String namedElementPackageName(NamedElement namedElement) {
return fqName((Namespace) namedElement.eContainer(), ".", true).toLowerCase();
return fqName((Namespace) namedElement.eContainer(), ".", true).toLowerCase().replaceAll("_default_transferobjecttypes/", "");
}

public static String namedElementParentPath(NamedElement namedElement) {
return fqName((Namespace) namedElement.eContainer(), "/", true).toLowerCase();
return fqName((Namespace) namedElement.eContainer(), "/", true).toLowerCase().replaceAll("_default_transferobjecttypes/", "");
}

public static String namedElementLogicalName(NamedElement namedElement) {
Expand All @@ -135,30 +135,22 @@ public static String namedElementVariableName(NamedElement namedElement) {
return safeName(StringUtils.uncapitalize(namedElement.getName()));
}

public static String transferObjectRelationParentPath(NamedElement namedElement) {
return safeNamedElementOriginalNameForClassNames((NamedElement) namedElement.eContainer()) +
'/' + namedElement.getName();
}

public static String fqNames(NamedElement namedElement) {
return fqName((Namespace) namedElement.eContainer(), ".", false) + '.' + namedElement.getName();
}


public static String relationAsmFqName(TransferObjectRelation transferObjectRelation) {
TransferObjectType transferObjectType = (TransferObjectType) transferObjectRelation.eContainer();
return fqName((Namespace) transferObjectType.eContainer(), ".", false) + '.' + transferObjectType.getName() + "#" + transferObjectRelation.getName();
return fqName(transferObjectType.getNamespace(), ".", false) + '.' + transferObjectType.getName() + "#" + transferObjectRelation.getName();
}

public static String classifierAsmFqName(NamedElement namedElement) {
TransferObjectType transferObjectType = (TransferObjectType) namedElement.eContainer();
NamedElement namedElement1 = transferObjectType;
public static String classifierAsmFqName(TransferObjectType transferObjectType) {
return fqName(transferObjectType.getNamespace(), ".", false) + '.' + transferObjectType.getName();
}

public static String attributeAsmFqName(TransferAttribute transferAttribute) {
TransferObjectType transferObjectType = (TransferObjectType) transferAttribute.eContainer();
NamedElement namedElement = transferObjectType;
if (isEntity(transferObjectType)) {
namedElement1 = getEntity(transferObjectType);
namedElement = getEntity(transferObjectType);
}
return fqName((Namespace) namedElement1.eContainer(), ".", false) + '.' + namedElement.getName() + "#" + namedElement.getName();
return fqName((Namespace) namedElement.eContainer(), ".", false) + '.' + namedElement.getName() + "#" + transferAttribute.getName();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import hu.blackbelt.judo.generator.commons.StaticMethodValueResolver;
import hu.blackbelt.judo.generator.commons.annotations.TemplateHelper;
import hu.blackbelt.judo.meta.psm.PsmUtils;
import hu.blackbelt.judo.meta.psm.accesspoint.AbstractActorType;
import hu.blackbelt.judo.meta.psm.accesspoint.ActorType;
import hu.blackbelt.judo.meta.psm.accesspoint.MappedActorType;
import hu.blackbelt.judo.meta.psm.data.BoundOperation;
import hu.blackbelt.judo.meta.psm.derived.StaticData;
import hu.blackbelt.judo.meta.psm.derived.StaticNavigation;
Expand All @@ -40,6 +42,7 @@

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static hu.blackbelt.judo.psm.generator.jackson.api.JavaNamespaceHelper.*;

Expand Down Expand Up @@ -160,17 +163,11 @@ public static EList<TransferOperation> getAllOperations(final TransferObjectType
}

public static Set<TransferObjectType> allExposedTransferObjectWithOperation(Model model) {
return modelWrapper(model).getStreamOfPsmAccesspointActorType().flatMap(access -> getAllExposedTransferObjectTypesFromAccessPointWithOperation(access).stream()).collect(Collectors.toSet());
return modelWrapper(model).getStreamOfPsmAccesspointAbstractActorType().flatMap(access -> getAllExposedTransferObjectTypesFromAccessPointWithOperation(access).stream()).collect(Collectors.toSet());
}

public static Model getModel(EObject element) {
EObject container = element;
while (container != null) {
if (container instanceof Model) {
return (Model) container;
}
container = container.eContainer();
}
return null;
public static List<AbstractActorType> allAccessPointActor(Model model) {
return modelWrapper(model).getStreamOfPsmAccesspointAbstractActorType().toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ public static boolean hasCustomOperation(TransferObjectType transferObjectType)
return transferObjectType.getOperations().stream().filter(OperationHelper::isCustomOperation).count() > 0;
}


/*
public static void collectOperations(TransferObjectType transferObjectType, Set<TransferOperation> operations) {
operations.addAll(transferObjectType.getOperations());
if (isMapped(transferObjectType)) {
MappedTransferObjectType mappedTransferObjectType = (MappedTransferObjectType) transferObjectType;
EntityType entityType = mappedTransferObjectType.getEntityType();
for (EntityType superType : entityType.getSuperEntityTypes()) {
}
}
if (transferObjectType.)
}
*/

public static List<TransferOperation> allOperations(TransferObjectType transferObjectType) {
return transferObjectType.getOperations().stream()
.filter(o -> o.getBehaviour() == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static boolean hasFaults(TransferOperation transferOperation) {
return transferOperation.getFaults().size() > 0;
}


public static String operationAsmFqName(TransferOperation transferOperation) {
TransferObjectType transferObjectType = (TransferObjectType) transferOperation.eContainer();
NamedElement namedElement = transferObjectType;
Expand Down Expand Up @@ -130,63 +129,62 @@ public static String toJAXRSPath(TransferOperation transferOperation, Model mode
}
} else if (behaviourType == TransferOperationBehaviourType.CREATE_INSTANCE) {
if (isBoundOperation(transferOperation)) {
path = transferObjectRelationParentPath((NamedElement) owner.eContainer()) + "/~update/" + owner.getName() + "/~create";
path = classifierAsmFqName((TransferObjectType) owner.eContainer()) + "/~update/" + owner.getName() + "/~create";
} else {
path = relationAsmFqName((TransferObjectRelation) owner) + "/~create/";
}
} else if (behaviourType == TransferOperationBehaviourType.VALIDATE_CREATE) {
if (isBoundOperation(transferOperation)) {
path = transferObjectRelationParentPath((NamedElement) owner.eContainer()) + "/~update/" + owner.getName() + "/~validate";
path = classifierAsmFqName((TransferObjectType) owner.eContainer()) + "/~update/" + owner.getName() + "/~validate";
} else {
path = relationAsmFqName((TransferObjectRelation) owner) + "/~create/";
}
} else if (behaviourType == TransferOperationBehaviourType.REFRESH) {
path = transferObjectRelationParentPath(owner) + "/~get/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~get/";
} else if (behaviourType == TransferOperationBehaviourType.UPDATE_INSTANCE) {
path = transferObjectRelationParentPath(owner) + "/~update/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~update/";
} else if (behaviourType == TransferOperationBehaviourType.VALIDATE_UPDATE) {
path = transferObjectRelationParentPath(owner) + "/~validate/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~validate/";
} else if (behaviourType == TransferOperationBehaviourType.DELETE_INSTANCE) {
path = transferObjectRelationParentPath(owner) + "/~delete/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~delete/";
} else if (behaviourType == TransferOperationBehaviourType.SET_REFERENCE) {
path = transferObjectRelationParentPath((NamedElement) owner.eContainer()) + "/~update/" + owner.getName() + "/~set";
path = classifierAsmFqName((TransferObjectType) owner.eContainer()) + "/~update/" + owner.getName() + "/~set";
} else if (behaviourType == TransferOperationBehaviourType.UNSET_REFERENCE) {
path = transferObjectRelationParentPath((NamedElement) owner.eContainer()) + "/~update/" + owner.getName() + "/~unset";
path = classifierAsmFqName((TransferObjectType) owner.eContainer()) + "/~update/" + owner.getName() + "/~unset";
} else if (behaviourType == TransferOperationBehaviourType.ADD_REFERENCE) {
path = transferObjectRelationParentPath((NamedElement) owner.eContainer()) + "/~update/" + owner.getName() + "/~add";
path = classifierAsmFqName((TransferObjectType) owner.eContainer()) + "/~update/" + owner.getName() + "/~add";
} else if (behaviourType == TransferOperationBehaviourType.REMOVE_REFERENCE) {
path = transferObjectRelationParentPath((NamedElement) owner.eContainer()) + "/~update/" + owner.getName() + "/~remove";
path = classifierAsmFqName((TransferObjectType) owner.eContainer()) + "/~update/" + owner.getName() + "/~remove";
} else if (behaviourType == TransferOperationBehaviourType.GET_RANGE) {
if(owner instanceof TransferObjectRelation) {
if (owner instanceof TransferObjectRelation) {
path = relationAsmFqName((TransferObjectRelation) owner) + "/~range/";
}else {
} else {
path = operationAsmFqName((TransferOperation) owner) + "/~range/";
}
path = transferObjectRelationParentPath(owner) + "/~range/";
} else if (behaviourType == TransferOperationBehaviourType.GET_TEMPLATE) {
path = transferObjectRelationParentPath(owner) + "/~template/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~template/";
} else if (behaviourType == TransferOperationBehaviourType.GET_PRINCIPAL) {
path = transferObjectRelationParentPath(owner) + "/~principal/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~principal/";
} else if (behaviourType == TransferOperationBehaviourType.GET_METADATA) {
path = transferObjectRelationParentPath(owner) + "/~meta/";
path = classifierAsmFqName((TransferObjectType) owner) + "/~meta/";
} else if (behaviourType == TransferOperationBehaviourType.GET_UPLOAD_TOKEN) {
path = transferObjectRelationParentPath(owner) + "/~upload-token/";
path = attributeAsmFqName((TransferAttribute) owner) + "/~upload-token/";
}

}

return path.replaceAll("^" + model.getName(),"").replaceAll("\\.","/").replaceAll("#","/");
return path.replaceAll("^" + model.getName() + "\\.", "").replaceAll("\\.", "/").replaceAll("#", "/").replaceAll("_default_transferobjecttypes/", "");
}

public static Boolean isMany(Parameter parameter) {
public static Boolean isMany(Parameter parameter) {
return parameter.getCardinality().getUpper() == -1;
}

public static Boolean operationOutputTypeDefined(TransferOperation transferOperation) {
if(!hasReturn(transferOperation)) {
public static Boolean operationOutputTypeDefined(TransferOperation transferOperation) {
if (!hasReturn(transferOperation)) {
return false;
}
return transferOperation.getOutput().getType() !=null;
return transferOperation.getOutput().getType() != null;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
templates:
- name: ApplicationConfig.java
- name: application.config.java
pathExpression: "'/' + #namedElementApiParentPath(#self) + '/' + #applicationClassName(#self) + '.java'"
templateName: rest/api/ApplicationConfig.java.hbs
actorTypeBased: true
templateName: rest/api/application.config.java.hbs
factoryExpression: "#allAccessPointActor(#model)"
actorTypeBased: false

- name: RestService.java
- name: rest.service.java
pathExpression: "'/' + #namedElementApiRestParentPath(#self) + '/' + #className(#self) + '.java'"
templateName: rest/api/RestService.java.hbs
templateName: rest/api/rest.service.java.hbs
factoryExpression: "#allExposedTransferObjectWithOperation(#model)"
actorTypeBased: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public interface {{ self.className }} {
{{/if}}
{{#if operation.hasParam}}
{{#if operation.input.isMany }}
, java.util.List<java.util.Map<java.lang.String, java.lang.Object>> {{operation.input.name}}
, java.util.List<java.util.Map<java.lang.String, java.lang.Object>> {{operation.input.name.firstToLower}}
{{else}}
, java.util.Map<java.lang.String, java.lang.Object> {{operation.input.name}}
, java.util.Map<java.lang.String, java.lang.Object> {{operation.input.name.firstToLower}}
{{/if}}
{{/if}}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static String implPackageName() {
}

public static String namedElementImplParentPath(NamedElement namedElement) {
return implPackageName().replaceAll("\\.", "/" ) + namedElementParentPath(namedElement);
return implPackageName().replaceAll("\\.", "/") + namedElementParentPath(namedElement);
}

public static String namedElementImplPackageName(NamedElement namedElement) {
Expand All @@ -56,25 +56,28 @@ public static String namedElementImplRestPackageName(NamedElement namedElement)
return implPackageName() + REST + "." + namedElementPackageName(namedElement);
}

public static String namedElementImplRestFqName(NamedElement namedElement) {
return implPackageName() + REST + "." + namedElementPackageName(namedElement) +
"." + safeNamedElementOriginalNameForClassNames(namedElement);
public static String namedElementImplRestParentPath(NamedElement namedElement) {
return implPackageName().replaceAll("\\.", "/") + REST + "/" + namedElementParentPath(namedElement);
}

public static String namedElementImplRestParentPath(NamedElement namedElement) {
return implPackageName().replaceAll("\\.", "/" ) + REST + "/" + namedElementParentPath(namedElement);
public static String applicationImplClassName(NamedElement namedElement) {
return StringUtils.capitalize(safeName(namedElement.getName()) + "ApplicationConfigImpl");
}

public static String applicationImplClassName(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName()) + "ApplicationConfigImpl" );
public static String implClassName(NamedElement namedElement) {
return StringUtils.capitalize(safeName(namedElement.getName()) + "Impl");
}

public static String implClassName(TransferObjectType transferObjectType) {
return StringUtils.capitalize(safeName(transferObjectType.getName()) + "Impl");
public static String variableName(NamedElement namedElement) {
return (namedElementPackageName(namedElement) + "_" + implClassName(namedElement)).replaceAll("\\.", "_");
}

public static String variableName(TransferObjectType transferObjectType) {
return (namedElementPackageName(transferObjectType) + "_" + implClassName(transferObjectType)).replaceAll("\\.","_") ;
public static String applicationImplFqName(NamedElement namedElement) {
return namedElementImplPackageName(namedElement) + "." + applicationImplClassName(namedElement);
}

public static String namedElementImplRestFqName(NamedElement namedElement) {
return namedElementImplRestPackageName(namedElement) + "." + implClassName(namedElement);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
templates:
- name: ApplicationConfigImpl.java
- name: application.config.impl.java
pathExpression: "'/' + #namedElementImplParentPath(#self) + '/' + #applicationImplClassName(#self) + '.java'"
templateName: rest/impl/ApplicationConfigImpl.java.hbs
actorTypeBased: true
templateName: rest/impl/application.config.impl.java.hbs
factoryExpression: "#allAccessPointActor(#model)"
actorTypeBased: false

- name: RestServiceImpl.java
- name: rest.service.impl.java
pathExpression: "'/' + #namedElementImplRestParentPath(#self) + '/' + #implClassName(#self) + '.java'"
templateName: rest/impl/RestServiceImpl.java.hbs
templateName: rest/impl/rest.service.impl.java.hbs
factoryExpression: "#allExposedTransferObjectWithOperation(#model)"
actorTypeBased: false
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class {{ applicationImplClassName self }} extends javax.ws.rs.core.Applic
private final java.util.Map<java.lang.String, java.lang.Object> properties = new java.util.TreeMap();

{{#each self.getAllExposedTransferObjectTypesFromAccessPointWithOperation as | to | }}
{{namedElementImplRestPackageName to}}.{{implClassName to}} {{variableName to}};
{{namedElementImplRestFqName}} {{variableName to}};
{{/each}}

@Override
Expand Down
Loading

0 comments on commit 37ee397

Please sign in to comment.