modelResources = modelResourcesDao.loadModelResourceByModelId(modelInstId);
}
HashMap<Integer, ModelResources> modResourcesIds = new HashMap<Integer, ModelResources>();
if(modelResources != null){
for(int i =0;i<modelResources.size(); i++){
ModelResources mr = modelResources.get(i);
modResourcesIds.put(mr.getResourceId(), mr);
}
}
//extract all resources
Vector resourcesIds = new Vector<Integer>();
List<Resource> allResources = (List<Resource>)getSessionContainer().getAttribute("ALL_RESOURCES_LIST");
//if null than extract
if(allResources == null){
allResources = DAOFactory.getResourceDAO().loadPagedResourcesList(start,limit);
}
modelResourcesExtendedListCreate(modelResourcesExtenList, allResources, modResourcesIds);
logger.debug("Loaded model resources");
JSONArray modelsResourcesJSON = (JSONArray) SerializerFactory.getSerializer("application/json").serialize(modelResourcesExtenList,locale);
JSONObject modelsResourcesResponseJSON = createJSONResponsemodelsResourcesList(modelsResourcesJSON, modelResourcesExtenList.size());
writeBackToClient(new JSONSuccess(modelsResourcesResponseJSON));
} catch (Throwable e) {
logger.error("Exception occurred while retrieving model tree", e);
throw new SpagoBIServiceException(SERVICE_NAME,
"Exception occurred while retrieving model tree", e);
}
}else if(serviceType != null && serviceType.equalsIgnoreCase(MODELINST_RESOURCE_SAVE)){
JSONArray resToSaveJSON = getAttributeAsJSONArray("ids");
Integer modelId = getAttributeAsInteger("modelInstId");
try {
List ids = deserializeResourceJSONArray(resToSaveJSON);
List toAddIds = ids;
//loops over all model resources
List<ModelResources> mrs = modelResourcesDao.loadModelResourceByModelId(modelId);
for(int i=0; i< mrs.size(); i++){
ModelResources modelres = mrs.get(i);
if(!ids.contains(modelres.getResourceId())){
//to remove
modelResourcesDao.removeModelResource(modelId, modelres.getResourceId());
}else {
//already present so remove it from the list
toAddIds.remove(modelres.getResourceId());
}
}
//now adds new ones