Class AasIvmlMapper

java.lang.Object
de.iip_ecosphere.platform.configuration.ivml.AbstractIvmlModifier
de.iip_ecosphere.platform.configuration.ivml.AasIvmlMapper
All Implemented Interfaces:
DecisionVariableProvider

public class AasIvmlMapper extends AbstractIvmlModifier
Maps an IVML configuration generically into an AAS with references to IIP-Ecosphere.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • AasIvmlMapper

      public AasIvmlMapper(Supplier<net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration> cfgSupplier, IvmlGraphMapper graphMapper, AbstractIvmlModifier.ConfigurationChangeListener changeListener)
      Creates a mapper with default settings, e.g., short ids for meta IVML information are prefixed by "meta" (SHORTID_PREFIX_META) and the variable filter excludes all IVML constraint variables (FILTER_NO_CONSTRAINT_VARIABLES).
      Parameters:
      cfgSupplier - a supplier providing the actual configuration instance
      graphMapper - maps a graph from IVML to an internal structure
      changeListener - optional configuration change listener, may be null
      Throws:
      IllegalArgumentException - if cfgSupplier is null
  • Method Details

    • mapParent

      private static String mapParent(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
      Returns the name of the parent project of var while considering PARENT_MAPPING. If there is no mapping, the name of the parent project is returned.
      Parameters:
      var - the variable to map
      Returns:
      the (mapped) name of the (declaring) parent project
    • setShortIdToMeta

      public void setShortIdToMeta(Function<String,String> metaShortId)
      Defines a function that turns an IVML name for a meta value, e.g., type or status, into an AAS short id candidate. The result of a function call will be validated by AasUtils.fixId(String). The default value is to prefix a given name with "meta".
      Parameters:
      metaShortId - the functor, ignored if null
    • setVariableFilter

      public void setVariableFilter(Predicate<net.ssehub.easy.varModel.model.AbstractVariable> variableFilter)
      Defines a predicate acting as IVML variable filter, i.e., variables to be included into the configuration AAS.
      Parameters:
      variableFilter - the predicate, ignored if null
    • mapByType

      public void mapByType(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smBuilder, de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator)
      Maps cfg into the submodel represented by smBuilder.
      Parameters:
      smBuilder - the submodel builder representing the target
      iCreator - the invocables creator for operations
    • mapType

      private net.ssehub.easy.varModel.model.datatypes.IDatatype mapType(net.ssehub.easy.varModel.model.datatypes.IDatatype type)
      Maps the type of an IVML variable into the configuration submodel, usually searching for the top-most parent of compound types.
      Parameters:
      type - the type to map
      Returns:
      the mapped type, may be type
    • mapType

      private net.ssehub.easy.varModel.model.datatypes.Compound mapType(net.ssehub.easy.varModel.model.datatypes.Compound type)
      Maps the type of an IVML variable into the configuration submodel, usually searching for the top-most parent of compound types.
      Parameters:
      type - the type to map
      Returns:
      the mapped type, may be type
    • createTypeCollectionBuilder

      private static de.iip_ecosphere.platform.support.aas.SubmodelElementList.SubmodelElementListBuilder createTypeCollectionBuilder(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smBuilder, String typeName)
      Creates a AAS collection representing an IVML type.
      Parameters:
      smBuilder - the submodel builder
      typeName - the type name (turned into an AAS shortID)
      Returns:
      the collection builder
    • bindOperations

      public void bindOperations(de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder sBuilder)
      Binds the AAS operations.
      Parameters:
      sBuilder - the server builder
    • bind

      private static void bind(de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder sBuilder)
      Binds the AAS operations (ensure static lambda functions).
      Parameters:
      sBuilder - the server builder
    • bindTemplateOperations

      private static void bindTemplateOperations(de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder sBuilder)
      Binds the AAS template operations (ensure static lambda functions).
      Parameters:
      sBuilder - the server builder
    • instantiate

      private Object instantiate(AasIvmlMapper.InstantiationMode mode, String appId, String codeFile) throws ExecutionException
      Instantiates according to the given configurer.
      Parameters:
      mode - the instantiation mode
      appId - the app to build
      codeFile - the code file containing the implementation
      Returns:
      summary of instantiation results depending on mode, e.g., list of generated and downloadable template URIs for AasIvmlMapper.InstantiationMode.APPS_NO_DEPS else null
      Throws:
      ExecutionException - when the instantiation fails
    • fixZipConvention

      private static File fixZipConvention(File file)
      Checking and fixing ZIP file conventions for instantiation. The instantiation requires that either the project is directly located in the root folder of the ZIP or in a single contained folder having the same name as the ZIP file. If possible, through renaming/copying, we fix the second situation here.
      Parameters:
      file - the original ZIP file
      Returns:
      the fixed ZIP file, may be file
    • collectTemplates

      private Object collectTemplates(long startTime)
      Collects the generated templates, copies them to ConfigurationSetup.getArtifactsFolder() and returns the file names prefixed by ConfigurationSetup.getArtifactsUriPrefix() as JSON.
      Parameters:
      startTime - the time the generation started (as ms timestamp)
      Returns:
      the generated template archives
    • acceptTemplateFile

      private static boolean acceptTemplateFile(File file, long startTime)
      Returns whether file is acceptable for template copying/publishing.
      Parameters:
      file - the file to check
      startTime - the start timestamp of the generation
      Returns:
      true for acceptable, false else
    • getVariableTarget

      protected net.ssehub.easy.varModel.model.Project getVariableTarget(net.ssehub.easy.varModel.model.Project root, net.ssehub.easy.varModel.model.datatypes.IDatatype type, String name, List<String> meshes) throws ExecutionException
      Description copied from class: AbstractIvmlModifier
      Returns the target for a variable to be created.
      Overrides:
      getVariableTarget in class AbstractIvmlModifier
      Parameters:
      root - the root project (may be used as default)
      type - the actual type of the variable to be created, may be null then anyway no variable will be created
      name - optional name if the name may influence the target, may be null
      meshes - mesh project names in case of an application project, else ignored; may be null
      Returns:
      the target project
      Throws:
      ExecutionException - if model management operations fail
      See Also:
    • isAllowedForModification

      protected boolean isAllowedForModification(net.ssehub.easy.varModel.model.Project prj)
      Description copied from class: AbstractIvmlModifier
      Returns whether the given project is allowed for modification (other than root).
      Overrides:
      isAllowedForModification in class AbstractIvmlModifier
      Parameters:
      prj - the project
      Returns:
      true allowed, false else
      See Also:
    • getIvmlSubpath

      protected String getIvmlSubpath(net.ssehub.easy.varModel.model.Project project)
      Description copied from class: AbstractIvmlModifier
      Returns the IVML subpath for the given project.
      Specified by:
      getIvmlSubpath in class AbstractIvmlModifier
      Parameters:
      project - the project
      Returns:
      the subpath, may be null for a top-level or a non-writable project, may be empty for the top-level folder or a sub-folder
    • getIvmlConfigFolder

      private File getIvmlConfigFolder(EasySetup ep)
      Returns the actual IVML config folder.
      Parameters:
      ep - the EASy setup instance
      Returns:
      the config folder
    • createIvmlConfigPath

      protected File createIvmlConfigPath(String subpath, net.ssehub.easy.varModel.model.Project project)
      Description copied from class: AbstractIvmlModifier
      Creates an IVML configuration (not meta-model) model path with subpath and for project p.
      Specified by:
      createIvmlConfigPath in class AbstractIvmlModifier
      Parameters:
      subpath - the subpath, may be null for none
      project - the project to create the path for
      Returns:
      the file name/path
      See Also:
    • deleteGraph

      public Object deleteGraph(String appName, String meshName) throws ExecutionException
      Deletes a graph structure in IVML. [public for testing]
      Parameters:
      appName - the configured name of the application, may be empty or null to delete an individual mesh that is not yet linked into an app (will fail if still linked and deletion happens without appName
      meshName - the configured name of the service mesh to delete a specific mesh in appName, may be null or empty to delete the entire app
      Returns:
      null always
      Throws:
      ExecutionException - if setting the graph structure fails
    • deleteReferenceFromContainerValue

      private net.ssehub.easy.varModel.model.values.ContainerValue deleteReferenceFromContainerValue(net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.model.AbstractVariable search) throws ExecutionException
      Deletes a reference from a container value and sets the new value.
      Parameters:
      var - the variable to take the value from, may be null
      search - the variable declaration to search the reference for
      Returns:
      the new container value, may be null for not found
      Throws:
      ExecutionException - if re-assigning the value fails
    • isNonEmptyString

      private static boolean isNonEmptyString(String string)
      Returns whether string is a non-empty string.
      Parameters:
      string - the string to test
      Returns:
      true for a non-empty string, false for an empty string or null
    • setGraph

      public Object setGraph(String appName, String appValueEx, String meshName, String format, String value) throws ExecutionException
      Changes an application/graph structure in IVML. Application/mesh files are dynamically linked and require a different approach as, e.g., constants. [public for testing]
      Parameters:
      appName - the configured name of the application
      appValueEx - the application value as IVML expression, may be empty or null to indicate that just a mesh shall be modified
      meshName - the configured name of the service mesh (may be null or empty for none; used as import resolution if given, existing and format or value are not given).
      format - the format of the graph (may be null or empty for none).
      value - the value (may be null or empty for none).
      Returns:
      null always
      Throws:
      ExecutionException - if setting the graph structure fails
    • getApplicationProjectName

      private String getApplicationProjectName(String appName)
      Returns the IVML project name for an application.
      Parameters:
      appName - the application name
      Returns:
      the project name
    • prepareApplicationProject

      private void prepareApplicationProject(net.ssehub.easy.varModel.model.Project app, net.ssehub.easy.varModel.model.Project root, List<String> meshes) throws ExecutionException
      Prepares an application project, e.g., adds default imports.
      Parameters:
      app - the application project
      root - the root project
      meshes - the meshes to be added as imports, may be null for none
      Throws:
      ExecutionException - if adding imports fails
    • getMeshProjectName

      private String getMeshProjectName(String meshName)
      Returns the IVML project name for a service mesh.
      Parameters:
      meshName - the configured name of the service mesh
      Returns:
      the project name
    • prepareMeshProject

      private void prepareMeshProject(net.ssehub.easy.varModel.model.Project mesh, net.ssehub.easy.varModel.model.Project root) throws ExecutionException
      Prepares a mesh project, e.g., adds default imports.
      Parameters:
      mesh - the mesh project
      root - the root project
      Throws:
      ExecutionException - if adding imports fails
    • annotate

      private void annotate(net.ssehub.easy.varModel.model.Project prj) throws ExecutionException
      Annotates prj with the usual binding time.
      Parameters:
      prj - the project
      Throws:
      ExecutionException - if the annotation cannot be created
    • createAppProject

      private void createAppProject(String appName, String appValueEx, AasIvmlMapper.ModelResults results) throws net.ssehub.easy.varModel.model.ModelQueryException, net.ssehub.easy.basics.modelManagement.ModelManagementException, ExecutionException
      Writes an application project with the given new mesh variable.
      Parameters:
      appName - the application name
      appValueEx - the IVML value expression for the application
      results - collected result information
      Throws:
      net.ssehub.easy.varModel.model.ModelQueryException - if IVML types/variables cannot be found
      net.ssehub.easy.basics.modelManagement.ModelManagementException - if IVML types/variables cannot be found
      ExecutionException - if the application value cannot be set
    • isRefWithName

      private static boolean isRefWithName(String name, net.ssehub.easy.varModel.confModel.Configuration cfg, net.ssehub.easy.varModel.model.values.Value mVal)
      Returns if mVal is a reference to a variable with a field name with value name.
      Parameters:
      name - the name to look for
      cfg - the configuration to resolve the reference
      mVal - the value possibly containing a reference value
      Returns:
      true if it is a reference with the desired property, false else
    • getVilConfiguration

      protected net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration getVilConfiguration()
      Description copied from class: AbstractIvmlModifier
      Returns the actual VIL configuration. Shall be consistent with AbstractIvmlModifier.getIvmlConfiguration().
      Specified by:
      getVilConfiguration in class AbstractIvmlModifier
      Returns:
      the configuration
    • getIvmlConfiguration

      protected net.ssehub.easy.varModel.confModel.Configuration getIvmlConfiguration()
      Description copied from class: AbstractIvmlModifier
      Returns the actual IVML configuration. Shall be consistent with AbstractIvmlModifier.getVilConfiguration().
      Specified by:
      getIvmlConfiguration in class AbstractIvmlModifier
      Returns:
      the configuration
    • validateAndPropagate

      protected net.ssehub.easy.reasoning.core.reasoner.ReasoningResult validateAndPropagate(Predicate<net.ssehub.easy.varModel.model.Project> projectFilter)
      Description copied from class: AbstractIvmlModifier
      Validates the model and propagates values within the model.
      Specified by:
      validateAndPropagate in class AbstractIvmlModifier
      Parameters:
      projectFilter - optional filter on projects to reason on, may be null
      Returns:
      the reasoning result
    • reloadConfiguration

      protected void reloadConfiguration()
      Description copied from class: AbstractIvmlModifier
      Reloads the configuration model.
      Specified by:
      reloadConfiguration in class AbstractIvmlModifier
    • findOrCreateProject

      private net.ssehub.easy.varModel.model.Project findOrCreateProject(net.ssehub.easy.varModel.model.Project scope, String projectName, boolean find)
      Finds an existing IVML project in scope with given name or creates a new one with default freeze block.
      Parameters:
      scope - the scope to look for
      projectName - the project name
      find - try to find the project or directly create a new project
      Returns:
      the project, created or found
    • validateName

      private String validateName(IvmlGraphMapper.IvmlGraphNode node, int count)
      Validates the name of a node and if there is none, sets a pseudo name based on count.
      Parameters:
      node - the node to validate
      count - unique node counter per mesh
      Returns:
      the name of node
    • toId

      private static String toId(String string)
      Turns string into an identifier, i.e., each non-Java identifier characters into a "_".
      Parameters:
      string - the string to be checked
      Returns:
      the validated string, potentially modified to be an id
    • createMeshProject

      private void createMeshProject(String appName, String meshName, IvmlGraphMapper.IvmlGraph graph, AasIvmlMapper.ModelResults results) throws net.ssehub.easy.varModel.model.ModelQueryException, net.ssehub.easy.basics.modelManagement.ModelManagementException, ExecutionException
      Creates a mesh project for graph.
      Parameters:
      appName - the application name
      meshName - the mesh name
      graph - the graph to create the mesh project for
      results - the results to be modified as a side effect
      Throws:
      net.ssehub.easy.varModel.model.ModelQueryException - if IVML types/variables cannot be found
      net.ssehub.easy.basics.modelManagement.ModelManagementException - if IVML types/variables cannot be found
      ExecutionException - if setting IVML values fails
    • collectServices

      private static AasIvmlMapper.ServiceMap collectServices(net.ssehub.easy.varModel.confModel.Configuration cfg, net.ssehub.easy.varModel.model.datatypes.IDatatype serviceType)
      Collects all declared services.
      Parameters:
      cfg - the configuration to take the services from
      serviceType - the IVML data type used to select services
      Returns:
      a mapping between service names and configured IVML variables
    • findServiceVar

      private static net.ssehub.easy.varModel.model.AbstractVariable findServiceVar(AasIvmlMapper.ServiceMap services, String name)
      Finds a service as IVML variable.
      Parameters:
      services - the mapped services
      name - the service name to search for
      Returns:
      the service IVML variable, or null for not found
    • addOperations

      private void addOperations(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smBuilder, de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator)
      Adds the default AAS operations for obtaining information on the configuration model / changing the model.
      Parameters:
      smBuilder - the submodel builder representing the target
      iCreator - the invocables creator for operations
    • getLang

      static String getLang()
      Returns the language to be used for LangString.
      Returns:
      the language
    • getStringValueEmptyNull

      static String getStringValueEmptyNull(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
      Returns the string value of var. If the value is empty, return null.
      Parameters:
      var - the variable to read the string value from
      Returns:
      the string value or null
    • mapVariable

      void mapVariable(net.ssehub.easy.varModel.confModel.IDecisionVariable var, de.iip_ecosphere.platform.support.aas.SubmodelElementContainerBuilder builder, String id)
      Maps a single variable var into builder.
      Parameters:
      var - the variable to map as source
      builder - the builder as target (representing the parent of var)
      id - the id to use as variable name instead of the variable name itself, may be null for the variable name
    • addMetaProperties

      private void addMetaProperties(net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.model.datatypes.IDatatype varType, de.iip_ecosphere.platform.support.aas.SubmodelElementContainerBuilder varBuilder, String displayName)
      Adds the meta properties of var of type varType to varBuilder.
      Parameters:
      var - the variable to take the meta-properties from
      varType - the type of var (as we already have determined it)
      varBuilder - the AAS builder representing var to add the AAS properties to
      displayName - the displac name of var, may be null for none
    • setSemanticId

      private static void setSemanticId(de.iip_ecosphere.platform.support.aas.Property.PropertyBuilder pBuilder, String semanticId)
      Sets a semantic id if available.
      Parameters:
      pBuilder - the property builder
      semanticId - the semantic id, may be null
    • getValue

      private static Object getValue(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
      Returns the value of a variable.
      Parameters:
      var - the variable
      Returns:
      the value
    • deleteAasVariableMapping

      private static void deleteAasVariableMapping(de.iip_ecosphere.platform.support.aas.Submodel sm, String typeName, String varName)
      Deletes the mapping of the specified variable in the AAS.
      Parameters:
      sm - the submodel to delete from
      typeName - the type name
      varName - the variable name
    • mapVariableToAas

      private void mapVariableToAas(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smB, net.ssehub.easy.varModel.confModel.IDecisionVariable var)
      Maps var into the submodel represented by smB.
      Parameters:
      smB - the submodel builder
      var - the variable