boolean response1 = false;
boolean response2 = false;
Structure structure = (Structure) super.get(id);
String tomcatPath = System.getProperty("catalina.home");
String galleryDir = tomcatPath + File.separator + "webapps" +
File.separator + "hotel" + File.separator +
"resources" + File.separator + "images" +
File.separator + "imagesStruct" + structure.getId() +
File.separator + "gallery" + structure.getGallery().getId();
String structureDir = tomcatPath + File.separator + "webapps" +
File.separator + "hotel" + File.separator +
"resources" + File.separator + "images" +
File.separator + "imagesStruct" + structure.getId();
File galleryDirectory = new File(galleryDir);
File structureDirectory = new File(structureDir);
Set<Photo> photos = structure.getGallery().getPhotos();
if(photos.isEmpty()) {
if(galleryDirectory.isDirectory()) { DirectoryUtils.deleteDirectory(galleryDir); }
if(structureDirectory.isDirectory()) { DirectoryUtils.deleteDirectory(structureDir); }
galleryManager.remove(structure.getGallery());
super.remove(structure);
}
else {
Photo photo = photos.iterator().next();
String galleryDir2 = photo.getUrl();
String dirSmallPhoto = galleryDir + File.separator + "small";
String dirBigPhoto = galleryDir + File.separator + "big";
response1 = DirectoryUtils.deleteDirectory(dirSmallPhoto);
response2 = DirectoryUtils.deleteDirectory(dirBigPhoto);
DirectoryUtils.deleteDirectory(galleryDir);
DirectoryUtils.deleteDirectory(structureDir);
this.deletePhotos(structure.getGallery());
galleryManager.remove(structure.getGallery());
super.remove(structure);
}
}