@Override public MetadataKey resolveChilds(MetadataContext context, LocationKey partial) throws MetadataResolvingException, ConnectionException { // This is incomplete but you get the idea if (AMERICA.equalsIgnoreCase(partial.getContinent())) { if (ARGENTINA.equalsIgnoreCase(partial.getCountry())) { return newKey(AMERICA).withDisplayName(AMERICA) .withChild(newKey(ARGENTINA) .withChild(newKey(BUENOS_AIRES)) .withChild(newKey(LA_PLATA))) .build(); } return buildAmericaKey(); } else if (EUROPE.equalsIgnoreCase(partial.getContinent())) { return buildEuropeKey(); } else { throw new MetadataResolvingException("Invalid Continent", FailureCode.INVALID_METADATA_KEY); } }
private MetadataKey buildServiceKey(ForwardingSoapClient connection, WebServiceDefinition ws) { String serviceId = ws.getServiceId(); SoapMetadataResolver resolver = connection.getSoapClient(serviceId).getMetadataResolver(); MetadataKeyBuilder key = newKey(serviceId).withDisplayName(ws.getFriendlyName()); List<String> excludedOperations = ws.getExcludedOperations(); resolver.getAvailableOperations().stream() .filter(ope -> !excludedOperations.contains(ope)) .forEach(ope -> key.withChild(newKey(ope).withDisplayName(NameUtils.titleize(ope)))); return key.build(); } }
/** * Given a {@link MetadataKey}, this is navigated recursively cloning each {@link MetadataKey} of the tree structure creating a * {@link MultilevelMetadataKeyBuilder} and adding the partName of each {@link MetadataKey} found. * * @param key {@link MetadataKey} to be cloned and enriched * @param partOrderMapping {@link Map} that contains the mapping of the name of each part of the {@link MetadataKey} * @param level the current level of the part of the {@link MetadataKey} to be cloned and enriched * @return a {@link MetadataKeyBuilder} with the cloned and enriched keys */ private MetadataKeyBuilder cloneAndEnrichMetadataKey(MetadataKey key, Map<Integer, ParameterModel> partOrderMapping, int level) { final MetadataKeyBuilder keyBuilder = newKey(key.getId(), partOrderMapping.get(level).getName()).withDisplayName(key.getDisplayName()); key.getProperties().forEach(keyBuilder::withProperty); key.getChilds().forEach(childKey -> keyBuilder.withChild(cloneAndEnrichMetadataKey(childKey, partOrderMapping, level + 1))); return keyBuilder; } }
childBuilder = rootBuilder; } else { childBuilder.withChild(fieldBuilder); childBuilder = fieldBuilder;
@Test public void resolveMetadataWithNoRefDynamicConfig() throws Exception { location = builder().globalName(RESOLVER_WITH_IMPLICIT_DYNAMIC_CONFIG).addProcessorsPart().addIndexPart(0).build(); MetadataKey key = newKey(AMERICA).withChild(newKey(USA).withChild(newKey(SAN_FRANCISCO))).build(); final MetadataResult<ComponentMetadataDescriptor<OperationModel>> metadataResult = getComponentDynamicMetadata(key); assertFailureResult(metadataResult, 1); assertMetadataFailure(metadataResult.getFailures().get(0), "Configuration used for Metadata fetch cannot be dynamic", INVALID_CONFIGURATION, MetadataResolvingException.class.getName(), COMPONENT, ""); } }
@Test public void failToResolveWithMultipleChildren() throws MetadataResolvingException { exception.expect(MetadataResolvingException.class); exception.expectMessage("MetadataKey used for Metadata resolution must only have one child per level."); final MetadataKey invalidMetadataKey = newKey(AMERICA, CONTINENT) .withChild(newKey(USA, COUNTRY).withChild(newKey(SFO, CITY)).withChild(newKey(NY, CITY))).build(); setParameters(continentParam, countryParam, cityParam); setMetadataKeyIdModelProperty(LocationKey.class); keyIdObjectResolver = new MetadataKeyIdObjectResolver(componentModel); keyIdObjectResolver.resolve(invalidMetadataKey); }
private MetadataKey toMetadataKey(JsonElement jsonElement) { if (jsonElement.isJsonNull()) { return null; } JsonObject metadataKey = jsonElement.getAsJsonObject(); if (metadataKey.entrySet().isEmpty()) { return new NullMetadataKey(); } JsonElement id = metadataKey.get("id"); JsonElement displayName = metadataKey.get("displayName"); JsonElement partName = metadataKey.get("partName"); JsonElement childs = metadataKey.get("childs"); if (id != null && displayName != null && partName != null && childs != null) { MetadataKeyBuilder key = MetadataKeyBuilder.newKey(id.getAsString()) .withDisplayName(displayName.getAsString()) .withPartName(partName.getAsString()); childs.getAsJsonArray() .forEach(child -> key.withChild(toMetadataKey(child))); return key.build(); } return null; } }
@Override public MetadataKey resolveChilds(MetadataContext context, LocationKey partial) throws MetadataResolvingException, ConnectionException { // This is incomplete but you get the idea if (AMERICA.equalsIgnoreCase(partial.getContinent())) { if (ARGENTINA.equalsIgnoreCase(partial.getCountry())) { return newKey(AMERICA).withDisplayName(AMERICA) .withChild(newKey(ARGENTINA) .withChild(newKey(BUENOS_AIRES)) .withChild(newKey(LA_PLATA))) .build(); } return buildAmericaKey(); } else if (EUROPE.equalsIgnoreCase(partial.getContinent())) { return buildEuropeKey(); } else { throw new MetadataResolvingException("Invalid Continent", FailureCode.INVALID_METADATA_KEY); } }
/** * Given a {@link MetadataKey}, this is navigated recursively cloning each {@link MetadataKey} of the tree structure creating a * {@link MultilevelMetadataKeyBuilder} and adding the partName of each {@link MetadataKey} found. * * @param key {@link MetadataKey} to be cloned and enriched * @param partOrderMapping {@link Map} that contains the mapping of the name of each part of the {@link MetadataKey} * @param level the current level of the part of the {@link MetadataKey} to be cloned and enriched * @return a {@link MetadataKeyBuilder} with the cloned and enriched keys */ private MetadataKeyBuilder cloneAndEnrichMetadataKey(MetadataKey key, Map<Integer, ParameterModel> partOrderMapping, int level) { final MetadataKeyBuilder keyBuilder = newKey(key.getId(), partOrderMapping.get(level).getName()).withDisplayName(key.getDisplayName()); key.getProperties().forEach(keyBuilder::withProperty); key.getChilds().forEach(childKey -> keyBuilder.withChild(cloneAndEnrichMetadataKey(childKey, partOrderMapping, level + 1))); return keyBuilder; } }
childBuilder = rootBuilder; } else { childBuilder.withChild(fieldBuilder); childBuilder = fieldBuilder;
@Test public void resolveMetadataWithNoRefDynamicConfig() throws Exception { location = builder().globalName(RESOLVER_WITH_IMPLICIT_DYNAMIC_CONFIG).addProcessorsPart().addIndexPart(0).build(); MetadataKey key = newKey(AMERICA).withChild(newKey(USA).withChild(newKey(SAN_FRANCISCO))).build(); final MetadataResult<ComponentMetadataDescriptor<OperationModel>> metadataResult = getComponentDynamicMetadata(key); assertFailureResult(metadataResult, 1); assertMetadataFailure(metadataResult.getFailures().get(0), "Configuration used for Metadata fetch cannot be dynamic", INVALID_CONFIGURATION, MetadataResolvingException.class.getName(), COMPONENT, ""); } }