All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jeaf.RESTFunctions.ext Maven / Gradle / Ivy

There is a newer version: 1.24.1
Show newest version
extension java::Naming;
extension java::GeneratorCommons;
extension java::OpenAPIFunctions;
extension functions::RESTOperation;
extension functions::RESTResource;

cached boolean isBeanParam(uml::Parameter param):
	param.isStereotypeApplied("BeanParam") || param.type.isStereotypeApplied("BeanParam");
	
cached List[uml::Parameter] getBeanParams(uml::Operation operation):
	operation.ownedParameter.select(e| e.isInputParameter() && e.isBeanParam() == true);
	
cached boolean isPathParam(uml::Parameter param):
	param.isStereotypeApplied("PathParam");

cached boolean isHeaderParam(uml::Parameter param):
	param.isStereotypeApplied("HeaderParam");

cached boolean isQueryParam(uml::Parameter param):
	param.isStereotypeApplied("QueryParam");

cached boolean isCookieParam(uml::Parameter param):
	param.isStereotypeApplied("CookieParam");

cached boolean isRequestBody(uml::Parameter param):
    !(param.isPathParam() || param.isHeaderParam() || param.isQueryParam() || param.isBeanParam() || param.isCookieParam());
    
cached List[String] getBodyParamNames(JMM::RESTOperation operation):
    operation.ownedParameter.select(e|e.isRequestBody() && e.isInputParameter()).name;

cached boolean isPathParamProperty(uml::Property property):
	property.isStereotypeApplied("PathParam");

cached boolean isHeaderParamProperty(uml::Property property):
	property.isStereotypeApplied("HeaderParam");

cached boolean isQueryParamProperty(uml::Property property):
	property.isStereotypeApplied("QueryParam");

cached boolean isCookieParamProperty(uml::Property property):
	property.isStereotypeApplied("CookieParam");
	
cached List[JMM::PathParam] getPathParams(uml::Operation operation):
    operation.ownedParameter.typeSelect(JMM::PathParam);
    
cached List[JMM::QueryParam] getQueryParams(uml::Operation operation):
    operation.ownedParameter.typeSelect(JMM::QueryParam);

cached List[JMM::HeaderParam] getHeaderParams(uml::Operation operation):
    operation.ownedParameter.typeSelect(JMM::HeaderParam).select(e|e.isParameterSuppressed() == false);

cached List[JMM::CookieParam] getCookieParams(uml::Operation operation):
    operation.ownedParameter.typeSelect(JMM::CookieParam);

cached List[JMM::PathParam] getBeanPathParams(uml::Operation operation):
    operation.getBeanParams().type.getAllAttributesFromHierarchy().typeSelect(JMM::PathParam);
    
cached boolean usesCookies(JMM::RESTResource resource):
   resource.ownedOperation.typeSelect(JMM::RESTOperation).select(e|e.hasCookieParams()).size > 0;
   
cached boolean hasCookieParams(uml::Operation operation):
    (operation.getCookieParams().size + operation.getBeanParams().type.getAllAttributesFromHierarchy().typeSelect(JMM::CookieParam).size) > 0;
    
cached List[String] getBeanPathVariableNames(uml::Operation operation):
    operation.getBeanParams().getInternalBeanPathVariableNames();
    
List[String] getInternalBeanPathVariableNames(uml::Parameter beanParam):
    beanParam.type.getAllAttributesFromHierarchy().typeSelect(JMM::PathParam).do(beanParam);
    
private String do(JMM::PathParam pathParam, uml::Parameter beanParam):
    if pathParam.type.isOpenAPIDataType() then
      beanParam.name + "." + pathParam.asGetter() + "()." + pathParam.type.getAllAttributesFromHierarchy().first().asGetter() + "()"
    else 
	  beanParam.name + "." + pathParam.asGetter() + "()";
    
private String addPrefix(String text, String prefix):
    prefix + text;
    
cached List[String] getAllPathParams(uml::Operation operation):
    operation.getPathParams().getRESTPathParamName().addAll(operation.getBeanPathParams().getRESTPathParamName());   
    
cached List[String] getAllPathParamNamnes(uml::Operation operation):
    operation.getPathParams().getPathVariableName().addAll(operation.getBeanPathVariableNames());
    
cached String getPathVariableName(JMM::PathParam pathParam):
    if pathParam.type.isOpenAPIDataType() then
        pathParam.getPathVariableNameForDataType()
    else 
      pathParam.name;
      
cached String getPathVariableNameForDataType(JMM::PathParam pathParam):
    if ((JMM::POJO) pathParam.type).compositeDataType then
      pathParam.name + ".get" + ((JMM::POJO) pathParam.type).compositeDataTypePublicFieldName.toFirstUpper() + "()"
    else
      if ((JMM::ServiceObject) pathParam.type).compositeDataType then
	    pathParam.name + ".get" + ((JMM::ServiceObject) pathParam.type).compositeDataTypePublicFieldName.toFirstUpper() + "()"
      else
       pathParam.name + "." + pathParam.type.getAllAttributesFromHierarchy().select(e|e.isStatic == false).first().asGetter() + "()";
    

cached String getRESTPathParamName(JMM::PathParam param):
    if (param.value.length > 0) then
       param.value
    else
       param.name; 

cached String getRESTQueryParamName(JMM::QueryParam param):
    if (param.value.length > 0) then
       param.value
    else
       param.name; 

cached String getRESTHeaderParamName(JMM::HeaderParam param):
    if (param.value.length > 0) then
       param.value
    else
       param.name; 

cached String getRESTCookieParamName(JMM::CookieParam param):
    if (param.value.length > 0) then
       param.value
    else
       param.name; 


cached List[String] splitRESTPath(String path, List[String] paramNames, List[String] variableNames):
    JAVA com.anaptecs.jeaf.fwk.generator.util.OpenAPIHelper.splitRESTPath(java.lang.String, java.util.List, java.util.List);

cached boolean hasValidRESTResourcePath(JMM::RESTResource restResource):
    if restResource.path.length > 0
    then restResource.path.startsWith("/")
    else true;
    
cached boolean hasValidRESTResourcePath(JMM::RESTOperation operation):
    if operation.getRESTOperationPath().length > 0 || ((JMM::RESTResource)operation.owner).path.length > 0
    then true
    else false;
    
cached boolean hasValidOperationPath(JMM::RESTOperation operation):
    if operation.getRESTOperationPath().length > 0 && operation.path.startsWith("/") && operation.owner.isRESTResource() && operation.owner.asRESTResource().operationPathPrefix.length == 0
    then false
    else true;
    
    
cached boolean hasUnsupportedRequestBody(JMM::RESTOperation operation):
    if (operation.hasRequestBody() && operation.httpMethods.select(e|e.supportsRequestBody()).size > 0) || operation.hasRequestBody() == false
    then false
    else true;

cached boolean belongsToOpenAPISpec(JMM::RESTOperation operation):
    if operation.owner.getRelationships().typeSelect(uml::Dependency).source.typeSelect(JMM::OpenAPI3Specification) > 0
    then true
    else false;
    
cached List[JMM::OpenAPI3Specification] getOpenAPISpecifications(JMM::RESTOperation operation):
  ((JMM::RESTResource)operation.owner).getOpenAPISpecifications();

cached List[JMM::OpenAPI3Specification] getOpenAPISpecifications(JMM::RESTResource restResource):
  restResource.getRelationships().typeSelect(uml::Dependency).source.typeSelect(JMM::OpenAPI3Specification);
  
cached List[uml::Parameter] getOpenAPIIncomaptibleParameterTypes(JMM::RESTOperation operation) :
  if operation.getOpenAPISpecifications().size > 0
  then operation.ownedParameter.select(e|e.type.isIncompatibleOpenAPIType())
  else {};

cached List[JMM::OpenAPI3Specification] getOpenAPISpecificationsForType(uml::Type type):
  type.package.getRelationships().typeSelect(uml::Dependency).source.typeSelect(JMM::OpenAPI3Specification);
  

cached List[uml::Property] getOpenAPIIncompatibleBeanProperties(JMM::BeanParam beanParam) :
  if beanParam.getOpenAPISpecificationsForType().size  > 0
  then beanParam.ownedAttribute.select(e|e.type.isIncompatibleOpenAPIType())
  else {};
  
cached boolean isIncompatibleOpenAPIType(uml::Type type) :
  if type.fqn() == "java.time.LocalTime" || type.fqn() == "java.time.LocalDateTime"
  then true
  else false;
  
cached String asParamErrorMessage(uml::Parameter parameter) :
  parameter.type.fqn() + " " + parameter.name;
    
cached String asPropertyErrorMessage(uml::Property property) :
  property.type.fqn() + " " + property.name;
  
cached String getRESTPath(JMM::RESTResource resource):
	if getRESTPathPrefix().length > 0
	then 
		resource.buildRESTPath()
	else resource.path;
	
cached String buildRESTPath(JMM::RESTResource resource):
	if resource.path.length > 0
	then 
		getRESTPathPrefix() + resource.path
	else 
		getRESTPathPrefix();

	
cached String getRESTPathPrefix():
	JAVA com.anaptecs.jeaf.fwk.generator.util.GeneratorCommons.getRESTPathPrefix();


cached List[uml::Class] getCompositeDataTypes(JMM::RESTResource resource):
	resource.ownedOperation.getPathParams().type.select(e|e.isCompositeDataTypeForRESTResource()).addAll(resource.ownedOperation.getHeaderParams().type.select(e|e.isCompositeDataTypeForRESTResource())).addAll(resource.ownedOperation.getQueryParams().type.select(e|e.isCompositeDataTypeForRESTResource())).addAll(resource.ownedOperation.getBeanParams().type.getAllAttributesFromHierarchy().type.select(e|e.isCompositeDataTypeForRESTResource())).toSet();
	
cached boolean hasCompositeDataTypes(JMM::RESTResource resource):
	resource.getCompositeDataTypes().isEmpty == false;

cached boolean isCompositeDataTypeForRESTResource(uml::Type type):
   isStereotypeApplied(type, "OpenAPIDataType") && ((JMM::OpenAPIDataType) type).compositeDataType;
   
cached List[String] getAllRESTPathParamNames(uml::Operation operation):
    operation.getPathParams().getRESTPathParamName().addAll(operation.getBeanPathParams().getRESTPathParamName());
   
cached String getRESTProxyName(JMM::RESTResource service, boolean reactive):
    if reactive
    then service.name + "RESTProxyReactive"
    else service.name + "RESTProxy";




© 2015 - 2024 Weber Informatics LLC | Privacy Policy