@Test public void should_finish_initialization_of_assets_using_the_first_location() { Set<AssetStorageUnit> assets = new HashSet<AssetStorageUnit>(); AssetStorageUnit asu1 = new AssetStorageUnit(); Map<String, String> locations = new HashMap<String, String>(); locations.put("locationKey", "/assets/js/some-asset.css"); locations.put("anotherLocationKey", " asu1.setLocations(locations); assets.add(asu1); BundleStorageUnit bsu = new BundleStorageUnit("bundle-name"); bsu.setAssetStorageUnits(assets); Context context = mock(Context.class, Mockito.RETURNS_DEEP_STUBS); BundleUtils.finalize(bsu, context); assertThat(asu1.getName()).isEqualTo("some-asset"); assertThat(asu1.getType()).isEqualTo(AssetType.css); }
public static void finalize(BundleStorageUnit bsu, Context context) { LOG.trace("Finalizing configuration of bundle \"{}\"", bsu); if (StringUtils.isBlank(bsu.getName())) { String extractedName = PathUtils.extractLowerCasedName(bsu.getRelativePath()); bsu.setName(extractedName); LOG.trace("Name of the bundle extracted from its path: \"{}\"", extractedName); } if (bsu.getAssetStorageUnits() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { String firstFoundLocation = asu.getLocations().values().iterator().next(); if (StringUtils.isBlank(asu.getName())) { String extractedName = PathUtils.extractLowerCasedName(firstFoundLocation); asu.setName(extractedName); LOG.trace("Name of the asset extracted from its first location: \"{}\"", extractedName); } if (asu.getType() == null) { AssetType extractedType = AssetType.extractFromAssetLocation(firstFoundLocation); asu.setType(extractedType); LOG.trace("Type of the asset extracted from its first location: \"{}\"", extractedType); } for(Entry<String, String> entry : asu.getLocations().entrySet()) { if(entry.getKey().toLowerCase().trim().equals(ApiLocator.LOCATION_KEY)) { asu.setGeneratorUid(entry.getValue().toLowerCase().trim()); } } } if (context != null && context.getConfiguration().getProperties() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { Map<String, String> locations = asu.getLocations(); for (Entry<String, String> locationEntry : asu.getLocations().entrySet()) { locations.put(locationEntry.getKey(), StringUtils.substitute(locationEntry.getValue(), context.getConfiguration().getProperties())); } } } } }
BundleUtils { public static void finalize(BundleStorageUnit bsu, Context context) { LOG.trace("Finalizing configuration of bundle \"{}\"", bsu); if (StringUtils.isBlank(bsu.getName())) { String extractedName = PathUtils.extractLowerCasedName(bsu.getRelativePath()); bsu.setName(extractedName); LOG.trace("Name of the bundle extracted from its path: \"{}\"", extractedName); } if (bsu.getAssetStorageUnits() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { String firstFoundLocation = asu.getLocations().values().iterator().next(); if (StringUtils.isBlank(asu.getName())) { String extractedName = PathUtils.extractLowerCasedName(firstFoundLocation); asu.setName(extractedName); LOG.trace("Name of the asset extracted from its first location: \"{}\"", extractedName); } if (asu.getType() == null) { AssetType extractedType = AssetType.extractFromAssetLocation(firstFoundLocation); asu.setType(extractedType); LOG.trace("Type of the asset extracted from its first location: \"{}\"", extractedType); } for(Entry<String, String> entry : asu.getLocations().entrySet()) { if(entry.getKey().toLowerCase().trim().equals(ApiLocator.LOCATION_KEY)) { asu.setGeneratorUid(entry.getValue().toLowerCase().trim()); } } } if (context != null && context.getConfiguration().getProperties() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { Map<String, String> locations = asu.getLocations(); for (Entry<String, String> locationEntry : asu.getLocations().entrySet()) { locations.put(locationEntry.getKey(), StringUtils.substitute(locationEntry.getValue(), context.getConfiguration().getProperties())); } } } } } }
BundleUtils { public static void finalize(BundleStorageUnit bsu, Context context) { LOG.trace("Finalizing configuration of bundle \"{}\"", bsu); if (StringUtils.isBlank(bsu.getName())) { String extractedName = PathUtils.extractLowerCasedName(bsu.getRelativePath()); bsu.setName(extractedName); LOG.trace("Name of the bundle extracted from its path: \"{}\"", extractedName); } if (bsu.getAssetStorageUnits() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { String firstFoundLocation = asu.getLocations().values().iterator().next(); if (StringUtils.isBlank(asu.getName())) { String extractedName = PathUtils.extractLowerCasedName(firstFoundLocation); asu.setName(extractedName); LOG.trace("Name of the asset extracted from its first location: \"{}\"", extractedName); } if (asu.getType() == null) { AssetType extractedType = AssetType.extractFromAssetLocation(firstFoundLocation); asu.setType(extractedType); LOG.trace("Type of the asset extracted from its first location: \"{}\"", extractedType); } for(Entry<String, String> entry : asu.getLocations().entrySet()) { if(entry.getKey().toLowerCase().trim().equals(ApiLocator.LOCATION_KEY)) { asu.setGeneratorUid(entry.getValue().toLowerCase().trim()); } } } if (context != null && context.getConfiguration().getProperties() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { Map<String, String> locations = asu.getLocations(); for (Entry<String, String> locationEntry : asu.getLocations().entrySet()) { locations.put(locationEntry.getKey(), StringUtils.substitute(locationEntry.getValue(), context.getConfiguration().getProperties())); } } } } } private  BundleUtils(); }
BundleUtils { public static void finalize(BundleStorageUnit bsu, Context context) { LOG.trace("Finalizing configuration of bundle \"{}\"", bsu); if (StringUtils.isBlank(bsu.getName())) { String extractedName = PathUtils.extractLowerCasedName(bsu.getRelativePath()); bsu.setName(extractedName); LOG.trace("Name of the bundle extracted from its path: \"{}\"", extractedName); } if (bsu.getAssetStorageUnits() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { String firstFoundLocation = asu.getLocations().values().iterator().next(); if (StringUtils.isBlank(asu.getName())) { String extractedName = PathUtils.extractLowerCasedName(firstFoundLocation); asu.setName(extractedName); LOG.trace("Name of the asset extracted from its first location: \"{}\"", extractedName); } if (asu.getType() == null) { AssetType extractedType = AssetType.extractFromAssetLocation(firstFoundLocation); asu.setType(extractedType); LOG.trace("Type of the asset extracted from its first location: \"{}\"", extractedType); } for(Entry<String, String> entry : asu.getLocations().entrySet()) { if(entry.getKey().toLowerCase().trim().equals(ApiLocator.LOCATION_KEY)) { asu.setGeneratorUid(entry.getValue().toLowerCase().trim()); } } } if (context != null && context.getConfiguration().getProperties() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { Map<String, String> locations = asu.getLocations(); for (Entry<String, String> locationEntry : asu.getLocations().entrySet()) { locations.put(locationEntry.getKey(), StringUtils.substitute(locationEntry.getValue(), context.getConfiguration().getProperties())); } } } } } private  BundleUtils(); static boolean isValid(BundleStorageUnit bsu, BundleStorageLogBuilder log); static void finalize(BundleStorageUnit bsu, Context context); }
BundleUtils { public static void finalize(BundleStorageUnit bsu, Context context) { LOG.trace("Finalizing configuration of bundle \"{}\"", bsu); if (StringUtils.isBlank(bsu.getName())) { String extractedName = PathUtils.extractLowerCasedName(bsu.getRelativePath()); bsu.setName(extractedName); LOG.trace("Name of the bundle extracted from its path: \"{}\"", extractedName); } if (bsu.getAssetStorageUnits() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { String firstFoundLocation = asu.getLocations().values().iterator().next(); if (StringUtils.isBlank(asu.getName())) { String extractedName = PathUtils.extractLowerCasedName(firstFoundLocation); asu.setName(extractedName); LOG.trace("Name of the asset extracted from its first location: \"{}\"", extractedName); } if (asu.getType() == null) { AssetType extractedType = AssetType.extractFromAssetLocation(firstFoundLocation); asu.setType(extractedType); LOG.trace("Type of the asset extracted from its first location: \"{}\"", extractedType); } for(Entry<String, String> entry : asu.getLocations().entrySet()) { if(entry.getKey().toLowerCase().trim().equals(ApiLocator.LOCATION_KEY)) { asu.setGeneratorUid(entry.getValue().toLowerCase().trim()); } } } if (context != null && context.getConfiguration().getProperties() != null) { for (AssetStorageUnit asu : bsu.getAssetStorageUnits()) { Map<String, String> locations = asu.getLocations(); for (Entry<String, String> locationEntry : asu.getLocations().entrySet()) { locations.put(locationEntry.getKey(), StringUtils.substitute(locationEntry.getValue(), context.getConfiguration().getProperties())); } } } } } private  BundleUtils(); static boolean isValid(BundleStorageUnit bsu, BundleStorageLogBuilder log); static void finalize(BundleStorageUnit bsu, Context context);  }