refactoring
parent
85230de9bb
commit
46ae55e8dd
@ -1,83 +1,83 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server.mongoservice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
||||
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
|
||||
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class ConcessioneImageUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Sep 7, 2021
|
||||
*/
|
||||
public class ConcessioneImageUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConcessioneImageUtil.class);
|
||||
|
||||
/**
|
||||
* Gets the uploaded images for id.
|
||||
*
|
||||
* @param httpServletRequest the http servlet request
|
||||
* @param itemType the item type
|
||||
* @param itemId the item id
|
||||
* @param maxImages the max images
|
||||
* @return the uploaded images for id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<UploadedImageDV> getUploadedImagesForId(HttpServletRequest httpServletRequest, String itemType,
|
||||
String itemId, Integer maxImages) throws Exception {
|
||||
LOG.info("getUploadedImagesForId [itemId: " + itemId + ", itemType: " + itemType + "] called");
|
||||
|
||||
if (itemType == null)
|
||||
throw new Exception("Invalid parameter. The itemType is null");
|
||||
|
||||
if (itemId == null)
|
||||
throw new Exception("Invalid parameter. The itemId is null");
|
||||
|
||||
List<UploadedImageDV> listUI = null;
|
||||
|
||||
try {
|
||||
|
||||
if (itemType.equalsIgnoreCase("concessione")) {
|
||||
|
||||
LOG.info("Trying to get concessione for id " + itemId);
|
||||
ConcessioniMongoServiceIdentityProxy cms = new ConcessioniMongoServiceIdentityProxy(httpServletRequest);
|
||||
Concessione concessione = cms.getItemById(itemId);
|
||||
if (concessione != null) {
|
||||
LOG.info("For id " + itemId + ", got concessione " + concessione.getNome() + " from service");
|
||||
List<UploadedImage> images = concessione.getImmaginiRappresentative();
|
||||
|
||||
if (images != null) {
|
||||
listUI = new ArrayList<UploadedImageDV>();
|
||||
int max = maxImages < images.size() ? maxImages : images.size();
|
||||
for (int i = 0; i < max; i++) {
|
||||
UploadedImageDV ui = ConvertToDataViewModel.toUploadedImage(images.get(i));
|
||||
listUI.add(ui);
|
||||
}
|
||||
LOG.info("For id " + itemId + ", got " + listUI.size() + " image/s");
|
||||
}
|
||||
} else
|
||||
throw new Exception("Concessione with id '" + itemId + "' not available");
|
||||
}
|
||||
|
||||
return listUI;
|
||||
|
||||
} catch (Exception e) {
|
||||
String erroMsg = UploadedImage.class.getSimpleName() + " not available for "
|
||||
+ Concessione.class.getSimpleName() + " with id " + itemId;
|
||||
LOG.error(erroMsg, e);
|
||||
throw new Exception(erroMsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//package org.gcube.portlets.user.geoportaldataviewer.server.mongoservice;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//
|
||||
//import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||
//import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
||||
//import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
|
||||
//import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
///**
|
||||
// * The Class ConcessioneImageUtil.
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
// *
|
||||
// * Sep 7, 2021
|
||||
// */
|
||||
//public class ConcessioneImageUtil {
|
||||
//
|
||||
// private static final Logger LOG = LoggerFactory.getLogger(ConcessioneImageUtil.class);
|
||||
//
|
||||
// /**
|
||||
// * Gets the uploaded images for id.
|
||||
// *
|
||||
// * @param httpServletRequest the http servlet request
|
||||
// * @param itemType the item type
|
||||
// * @param itemId the item id
|
||||
// * @param maxImages the max images
|
||||
// * @return the uploaded images for id
|
||||
// * @throws Exception the exception
|
||||
// */
|
||||
// public List<UploadedImageDV> getUploadedImagesForId(HttpServletRequest httpServletRequest, String itemType,
|
||||
// String itemId, Integer maxImages) throws Exception {
|
||||
// LOG.info("getUploadedImagesForId [itemId: " + itemId + ", itemType: " + itemType + "] called");
|
||||
//
|
||||
// if (itemType == null)
|
||||
// throw new Exception("Invalid parameter. The itemType is null");
|
||||
//
|
||||
// if (itemId == null)
|
||||
// throw new Exception("Invalid parameter. The itemId is null");
|
||||
//
|
||||
// List<UploadedImageDV> listUI = null;
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// if (itemType.equalsIgnoreCase("concessione")) {
|
||||
//
|
||||
// LOG.info("Trying to get concessione for id " + itemId);
|
||||
// ConcessioniMongoServiceIdentityProxy cms = new ConcessioniMongoServiceIdentityProxy(httpServletRequest);
|
||||
// Concessione concessione = cms.getItemById(itemId);
|
||||
// if (concessione != null) {
|
||||
// LOG.info("For id " + itemId + ", got concessione " + concessione.getNome() + " from service");
|
||||
// List<UploadedImage> images = concessione.getImmaginiRappresentative();
|
||||
//
|
||||
// if (images != null) {
|
||||
// listUI = new ArrayList<UploadedImageDV>();
|
||||
// int max = maxImages < images.size() ? maxImages : images.size();
|
||||
// for (int i = 0; i < max; i++) {
|
||||
// UploadedImageDV ui = ConvertToDataViewModel.toUploadedImage(images.get(i));
|
||||
// listUI.add(ui);
|
||||
// }
|
||||
// LOG.info("For id " + itemId + ", got " + listUI.size() + " image/s");
|
||||
// }
|
||||
// } else
|
||||
// throw new Exception("Concessione with id '" + itemId + "' not available");
|
||||
// }
|
||||
//
|
||||
// return listUI;
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// String erroMsg = UploadedImage.class.getSimpleName() + " not available for "
|
||||
// + Concessione.class.getSimpleName() + " with id " + itemId;
|
||||
// LOG.error(erroMsg, e);
|
||||
// throw new Exception(erroMsg);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
Loading…
Reference in New Issue