test_class.declarator: agentService
test_class.modifier: private
test_class.original_string: private AgentService agentService;
test_class.type: AgentService
test_class.var_name: agentService
test_class.declarator: specificationProvider
test_class.modifier: private
test_class.original_string: private ELSpecificationProvider specificationProvider;
test_class.type: ELSpecificationProvider
test_class.var_name: specificationProvider
test_class.file: efm/efm-c2-protocol/efm-c2-protocol-framework/src/test/java/com/cloudera/cem/efm/service/agent/TestStaticELSpecificationProvider.java
test_class.identifier: TestStaticELSpecificationProvider
test_case.body: @Test
      public void testGetELSpecWhenVersionDoesNotExistAndSingleCompatible() {
          final String agentClass = "default";
          final AgentManifest defaultManifest = createAgentManifest("X.Y.Z", "minifi-java");
  
          when(agentService.getAgentManifests(agentClass)).thenReturn(Collections.singletonList(defaultManifest));
  
          final Optional<ELSpecification> specification = specificationProvider.getELSpecification(agentClass);
          assertTrue(specification.isPresent());
          assertEquals("minifi-java-0.6.0", specification.get().getSpecificationKey());
      }
test_case.class_method_signature: TestStaticELSpecificationProvider.testGetELSpecWhenVersionDoesNotExistAndSingleCompatible()
test_case.full_signature: @Test public void testGetELSpecWhenVersionDoesNotExistAndSingleCompatible()
test_case.identifier: testGetELSpecWhenVersionDoesNotExistAndSingleCompatible
test_case.invocations: createAgentManifest thenReturn when getAgentManifests singletonList getELSpecification assertTrue isPresent assertEquals getSpecificationKey get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetELSpecWhenVersionDoesNotExistAndSingleCompatible()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(StaticELSpecificationProvider.class)
focal_class.modifier: static final
focal_class.original_string: static final Logger LOGGER = LoggerFactory.getLogger(StaticELSpecificationProvider.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: MINIFI_CPP_TYPE = "minifi-cpp"
focal_class.modifier: static final
focal_class.original_string: static final String MINIFI_CPP_TYPE = "minifi-cpp";
focal_class.type: String
focal_class.var_name: MINIFI_CPP_TYPE
focal_class.declarator: MINIFI_JAVA_TYPE = "minifi-java"
focal_class.modifier: static final
focal_class.original_string: static final String MINIFI_JAVA_TYPE = "minifi-java";
focal_class.type: String
focal_class.var_name: MINIFI_JAVA_TYPE
focal_class.declarator: SPEC_FILENAME_PATTERN = Pattern.compile("el-(" + MINIFI_CPP_TYPE + "|" + MINIFI_JAVA_TYPE + ")-(.+)\\.json")
focal_class.modifier: static final
focal_class.original_string: static final Pattern SPEC_FILENAME_PATTERN = Pattern.compile("el-(" + MINIFI_CPP_TYPE + "|" + MINIFI_JAVA_TYPE + ")-(.+)\\.json");
focal_class.type: Pattern
focal_class.var_name: SPEC_FILENAME_PATTERN
focal_class.declarator: MINIFI_CPP_EL_BUNDLE_ARTIFACT = "minifi-expression-language-extensions"
focal_class.modifier: static final
focal_class.original_string: static final String MINIFI_CPP_EL_BUNDLE_ARTIFACT = "minifi-expression-language-extensions";
focal_class.type: String
focal_class.var_name: MINIFI_CPP_EL_BUNDLE_ARTIFACT
focal_class.declarator: specificationsDir
focal_class.modifier: private final
focal_class.original_string: private final String specificationsDir;
focal_class.type: String
focal_class.var_name: specificationsDir
focal_class.declarator: agentService
focal_class.modifier: private final
focal_class.original_string: private final AgentService agentService;
focal_class.type: AgentService
focal_class.var_name: agentService
focal_class.declarator: objectMapper
focal_class.modifier: private final
focal_class.original_string: private final ObjectMapper objectMapper;
focal_class.type: ObjectMapper
focal_class.var_name: objectMapper
focal_class.declarator: specificationKeys = new TreeSet<>()
focal_class.modifier: private final
focal_class.original_string: private final SortedSet<String> specificationKeys = new TreeSet<>();
focal_class.type: SortedSet<String>
focal_class.var_name: specificationKeys
focal_class.declarator: specifications = new HashMap<>()
focal_class.modifier: private final
focal_class.original_string: private final Map<String, ELSpecification> specifications = new HashMap<>();
focal_class.type: Map<String, ELSpecification>
focal_class.var_name: specifications
focal_class.file: efm/efm-c2-protocol/efm-c2-protocol-framework/src/main/java/com/cloudera/cem/efm/service/agent/StaticELSpecificationProvider.java
focal_class.identifier: StaticELSpecificationProvider
focal_class.interfaces: implements ELSpecificationProvider
focal_class.class_method_signature: StaticELSpecificationProvider.StaticELSpecificationProvider(final ELSpecificationProperties properties, final AgentService agentService, final ObjectMapper objectMapper)
focal_class.full_signature: @Autowired public  StaticELSpecificationProvider(final ELSpecificationProperties properties, final AgentService agentService, final ObjectMapper objectMapper)
focal_class.identifier: StaticELSpecificationProvider
focal_class.modifiers: @Autowired public
focal_class.parameters: (final ELSpecificationProperties properties, final AgentService agentService, final ObjectMapper objectMapper)
focal_class.signature:  StaticELSpecificationProvider(final ELSpecificationProperties properties, final AgentService agentService, final ObjectMapper objectMapper)
focal_class.class_method_signature: StaticELSpecificationProvider.loadSpecifications()
focal_class.full_signature: @PostConstruct public void loadSpecifications()
focal_class.identifier: loadSpecifications
focal_class.modifiers: @PostConstruct public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void loadSpecifications()
focal_class.class_method_signature: StaticELSpecificationProvider.printWarning()
focal_class.full_signature: private void printWarning()
focal_class.identifier: printWarning
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void printWarning()
focal_class.class_method_signature: StaticELSpecificationProvider.getELSpecification(final String agentClass)
focal_class.full_signature: @Override public Optional<ELSpecification> getELSpecification(final String agentClass)
focal_class.identifier: getELSpecification
focal_class.modifiers: @Override public
focal_class.parameters: (final String agentClass)
focal_class.return: Optional<ELSpecification>
focal_class.signature: Optional<ELSpecification> getELSpecification(final String agentClass)
focal_class.class_method_signature: StaticELSpecificationProvider.getCompatibleELSpecification(final String mappedType)
focal_class.full_signature: private Optional<ELSpecification> getCompatibleELSpecification(final String mappedType)
focal_class.identifier: getCompatibleELSpecification
focal_class.modifiers: private
focal_class.parameters: (final String mappedType)
focal_class.return: Optional<ELSpecification>
focal_class.signature: Optional<ELSpecification> getCompatibleELSpecification(final String mappedType)
focal_class.class_method_signature: StaticELSpecificationProvider.getKey(String agentType, String version)
focal_class.full_signature: private String getKey(String agentType, String version)
focal_class.identifier: getKey
focal_class.modifiers: private
focal_class.parameters: (String agentType, String version)
focal_class.return: String
focal_class.signature: String getKey(String agentType, String version)
focal_method.body: @Override
      public Optional<ELSpecification> getELSpecification(final String agentClass) {
          if (StringUtils.isBlank(agentClass)) {
              throw new IllegalArgumentException("AgentClass is required to obtain the EL specification");
          }
  
          final List<AgentManifest> agentManifests = agentService.getAgentManifests(agentClass);
          if (agentManifests.isEmpty()) {
              throw new IllegalArgumentException("No manifests exists for the given agent class");
          }
  
          final AgentManifest agentManifest = agentManifests.get(0);
          if (agentManifest.getAgentType() == null) {
              throw new IllegalArgumentException("AgentManifest AgentType is required to obtain the EL specification");
          }
  
          // determine the agent type for the key...
          String mappedType;
          final String agentType = agentManifest.getAgentType();
          if (agentType.equals(MINIFI_JAVA_TYPE) || agentType.equals("java")) {
              mappedType = MINIFI_JAVA_TYPE;
          } else if (agentType.equals(MINIFI_CPP_TYPE) || agentType.equals("cpp")) {
              mappedType = MINIFI_CPP_TYPE;
          } else {
              throw new IllegalArgumentException("Unexpected agent type '" + agentType + "'");
          }
  
  
          // determine the version for the key...
          String version = null;
          final BuildInfo buildInfo = agentManifest.getBuildInfo();
          if (buildInfo != null && buildInfo.getVersion() != null) {
              final String buildInfoVersion = buildInfo.getVersion();
              final int snapshotIndex = buildInfoVersion.indexOf("-SNAPSHOT");
              if (snapshotIndex > 0) {
                  version = buildInfoVersion.substring(0, snapshotIndex);
              } else {
                  version = buildInfoVersion;
              }
          }
  
          // if the type is CPP, check if the EL bundle is included, and if not then return an empty spec
          if (mappedType.equals(MINIFI_CPP_TYPE)) {
              boolean hasELBundle = false;
              if (agentManifest.getBundles() != null) {
                  for (final Bundle bundle : agentManifest.getBundles()) {
                      if (MINIFI_CPP_EL_BUNDLE_ARTIFACT.equals(bundle.getArtifact())) {
                          hasELBundle = true;
                          break;
                      }
                  }
              }
  
              if (!hasELBundle) {
                  final ELSpecification emptySpec = new ELSpecification();
                  emptySpec.setSpecificationKey("missing-el-bundle");
                  emptySpec.setOperations(Collections.emptyMap());
                  return Optional.of(emptySpec);
              }
          }
  
          // if version is null then we'll attempt to take the first EL spec using just the type, otherwise look for exact version
          if (version == null) {
              return getCompatibleELSpecification(mappedType);
          } else {
              final String key = getKey(mappedType, version);
              final ELSpecification exactSpecification = specifications.get(key);
              if (exactSpecification == null) {
                  LOGGER.warn("No EL specification was found for {}, attempting to find compatible specification", new Object[]{key});
                  return getCompatibleELSpecification(mappedType);
              } else {
                  return Optional.of(exactSpecification);
              }
          }
      }
focal_method.class_method_signature: StaticELSpecificationProvider.getELSpecification(final String agentClass)
focal_method.full_signature: @Override public Optional<ELSpecification> getELSpecification(final String agentClass)
focal_method.identifier: getELSpecification
focal_method.invocations: isBlank getAgentManifests isEmpty get getAgentType getAgentType equals equals equals equals getBuildInfo getVersion getVersion indexOf substring equals getBundles getBundles equals getArtifact setSpecificationKey setOperations emptyMap of getCompatibleELSpecification getKey get warn getCompatibleELSpecification of
focal_method.modifiers: @Override public
focal_method.parameters: (final String agentClass)
focal_method.return: Optional<ELSpecification>
focal_method.signature: Optional<ELSpecification> getELSpecification(final String agentClass)