Skip to content

Commit

Permalink
Removed redundant dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mechkg committed Jan 10, 2017
1 parent 3a7e176 commit 27be7f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import uk.ac.ncl.openlab.intake24.services.fooddb.errors.LocaleError;
import uk.ac.ncl.openlab.intake24.services.fooddb.errors.LookupError;
import uk.ac.ncl.openlab.intake24.services.fooddb.errors.NutrientMappingError;
import uk.ac.ncl.openlab.intake24.services.fooddb.images.ImageStorageService;
import uk.ac.ncl.openlab.intake24.services.fooddb.user.FoodDataSources;
import uk.ac.ncl.openlab.intake24.services.fooddb.user.FoodDatabaseService;
import uk.ac.ncl.openlab.intake24.services.fooddb.user.UserAsServedImage;
Expand All @@ -103,13 +102,12 @@ public class FoodLookupServiceImpl extends RemoteServiceServlet implements FoodL

private DataStore dataStore;
private FoodDatabaseService foodData;
private ImageStorageService imageStorage;

private Map<String, FoodIndex> foodIndexes;
private Map<String, Splitter> splitters;
private NutrientMappingService nutrientMappingService;

private String imageUrlBase;
private String imageUrlPrefix;

private Function1<String, String> resolveImageUrl;

Expand All @@ -126,7 +124,7 @@ public void init() throws ServletException {
Injector injector = (Injector) this.getServletContext().getAttribute("intake24.injector");

dataStore = injector.getInstance(DataStore.class);
imageStorage = injector.getInstance(ImageStorageService.class);

foodData = injector.getInstance(FoodDatabaseService.class);
foodIndexes = injector.getInstance(Key.get(new TypeLiteral<Map<String, FoodIndex>>() {
}));
Expand All @@ -135,12 +133,12 @@ public void init() throws ServletException {

nutrientMappingService = injector.getInstance(NutrientMappingService.class);

imageUrlBase = getServletContext().getInitParameter("image-url-base");
imageUrlPrefix = getServletContext().getInitParameter("image-url-prefix");

resolveImageUrl = new Function1<String, String>() {
@Override
public String apply(String argument) {
return imageStorage.getUrl(argument);
return imageUrlPrefix + "/" + argument;
}
};

Expand Down Expand Up @@ -341,7 +339,7 @@ public AsServedDef getAsServedDef(String asServedSet, String locale) {
UserAsServedImage img = iter.next();

images[i++] = new AsServedDef.ImageInfo(
new ImageDef(imageStorage.getUrl(img.mainImagePath()), imageStorage.getUrl(img.thumbnailPath()), labelForAsServed(img.weight())),
new ImageDef(resolveImageUrl.apply(img.mainImagePath()), resolveImageUrl.apply(img.thumbnailPath()), labelForAsServed(img.weight())),
img.weight());
}

Expand Down Expand Up @@ -369,11 +367,11 @@ private ImageMapDefinition toJavaImageMap(UserImageMap imageMap) {

while (iterator.hasNext()) {
UserImageMapObject obj = iterator.next();
areas.add(new Area(new Polygon(obj.outline()), imageStorage.getUrl(obj.overlayPath()), obj.id()));
areas.add(new Area(new Polygon(obj.outline()), resolveImageUrl.apply(obj.overlayPath()), obj.id()));
navigation[counter++] = obj.id();
}

return new ImageMapDefinition(imageStorage.getUrl(imageMap.baseImagePath()), areas.toArray(new Area[areas.size()]), new int[][] {
return new ImageMapDefinition(resolveImageUrl.apply(imageMap.baseImagePath()), areas.toArray(new Area[areas.size()]), new int[][] {
navigation
});
}
Expand All @@ -400,7 +398,7 @@ public DrinkwareDef getDrinkwareDef(String drinkwareId, String locale) {
while (iter.hasNext()) {
uk.ac.ncl.openlab.intake24.DrinkScale def = iter.next();

scaleDefs.add(new DrinkScaleDef(def.choice_id(), imageUrlBase + "/" + def.baseImage(), imageUrlBase + "/" + def.overlayImage(), def.width(),
scaleDefs.add(new DrinkScaleDef(def.choice_id(), imageUrlPrefix + "/" + def.baseImage(), imageUrlPrefix + "/" + def.overlayImage(), def.width(),
def.height(), def.emptyLevel(), def.fullLevel(), def.vf().asArray()));
}

Expand Down Expand Up @@ -476,7 +474,7 @@ public FoodData getFoodData(String foodCode, String locale) {

@Override
public PortionSizeMethod getWeightPortionSizeMethod() {
return new PortionSizeMethod("weight", "weight", imageUrlBase + "/portion/weight.png", true, new HashMap<String, String>());
return new PortionSizeMethod("weight", "weight", imageUrlPrefix + "/portion/weight.png", true, new HashMap<String, String>());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ protected DataSource foodDatabase(Injector injector) {

return new HikariDataSource(cpConfig);
}

@Provides
@Singleton
protected ImageStorageService imageStorageService() {
return new ImageStorageLocal(new LocalImageStorageSettings(webXmlConfig.get("image-storage-local-directory"), webXmlConfig.get("image-storage-local-url-prefix")));
}


@Override
protected void configure() {
Expand Down

0 comments on commit 27be7f3

Please sign in to comment.