RequestContainer reqCont = getRequestContainer();
SessionContainer sessCont = reqCont.getSessionContainer();
SessionContainer permSess = sessCont.getPermanentContainer();
IEngUserProfile profile = (IEngUserProfile)permSess.getAttribute(IEngUserProfile.ENG_USER_PROFILE);
IObjMetadataDAO dao=DAOFactory.getObjMetadataDAO();
dao.setUserProfile(profile);
ObjMetadata metaNew = recoverObjMetadataDetails(serviceRequest);
EMFErrorHandler errorHandler = getErrorHandler();
// if there are some validation errors into the errorHandler does not write into DB
Collection errors = errorHandler.getErrors();
if (errors != null && errors.size() > 0) {
Iterator iterator = errors.iterator();
while (iterator.hasNext()) {
Object error = iterator.next();
if (error instanceof EMFValidationError) {
serviceResponse.setAttribute("metaObj", metaNew);
serviceResponse.setAttribute("modality", mod);
return;
}
}
}
if (mod.equalsIgnoreCase(SpagoBIConstants.DETAIL_INS)) {
//if a ds with the same label not exists on db ok else error
if (dao.loadObjMetadataByLabel(metaNew.getLabel()) != null){
HashMap params = new HashMap();
params.put(AdmintoolsConstants.PAGE, ListObjMetadataModule.MODULE_PAGE);
EMFUserError error = new EMFUserError(EMFErrorSeverity.ERROR, 13004, new Vector(), params );
getErrorHandler().addError(error);
return;
}
dao.insertObjMetadata(metaNew);
ObjMetadata tmpMeta = dao.loadObjMetadataByLabel(metaNew.getLabel());
metaNew.setObjMetaId(tmpMeta.getObjMetaId());
mod = SpagoBIConstants.DETAIL_MOD;
} else {
//update metadata
dao.modifyObjMetadata(metaNew);
}
IDomainDAO domaindao = DAOFactory.getDomainDAO();
List dataTypes = domaindao.loadListDomainsByType("OBJMETA_DATA_TYPE");
serviceResponse.setAttribute(OBJMETA_DATA_TYPE, dataTypes);