*
* @throws EMFUserError
*/
private void importFunctionalities() throws EMFUserError {
logger.debug("IN");
SbiFunctions functToInsert = null;
try {
List exportedFuncts = importer.getAllExportedSbiObjects(sessionExpDB, "SbiFunctions", null);
while (exportedFuncts.size() != 0) {
Iterator iterSbiFuncts = exportedFuncts.iterator();
int minEl = 1000;
SbiFunctions funct = null;
// search the functionality for insert
while (iterSbiFuncts.hasNext()) {
funct = (SbiFunctions) iterSbiFuncts.next();
String path = funct.getPath();
int numEl = path.split("/").length; // the number of levels
if (numEl < minEl) {
minEl = numEl;
functToInsert = funct;
}
}
// remove function from list
exportedFuncts = removeFromList(exportedFuncts, functToInsert);
logger.info("Insert the Funtionality (Path):" + functToInsert.getPath());
// insert function
Integer expId = functToInsert.getFunctId();
Map functIdAss = metaAss.getFunctIDAssociation();
Set functIdAssSet = functIdAss.keySet();
// if the functionality is present skip the insert
if (functIdAssSet.contains(expId)) {
logger.info("Exported functionality " + functToInsert.getName() + " not inserted"
+ " because it has the same label (and the same path) of an existing functionality");
metaLog.log("Exported functionality " + functToInsert.getName() + " not inserted"
+ " because it has the same label (and the same path) of an existing functionality");
continue;
}
SbiFunctions newFunct = ImportUtilities.makeNewSbiFunction(functToInsert);
String functCd = functToInsert.getFunctTypeCd();
Map unique = new HashMap();
unique.put("valuecd", functCd);
unique.put("domaincd", "FUNCT_TYPE");
SbiDomains existDom = (SbiDomains) importer.checkExistence(unique, sessionCurrDB, new SbiDomains());
if (existDom != null) {
newFunct.setFunctType(existDom);
newFunct.setFunctTypeCd(existDom.getValueCd());
}
String path = newFunct.getPath();
String parentPath = path.substring(0, path.lastIndexOf('/'));
Query hibQuery = sessionCurrDB.createQuery(" from SbiFunctions where path = '" + parentPath + "'");
SbiFunctions functParent = (SbiFunctions) hibQuery.uniqueResult();
if (functParent != null) {
newFunct.setParentFunct(functParent);
}
// manages prog column that determines the folders order
if (functParent == null)
newFunct.setProg(new Integer(1));
else {
// loads sub functionalities
Query query = sessionCurrDB
.createQuery("select max(s.prog) from SbiFunctions s where s.parentFunct.functId = "
+ functParent.getFunctId());
Integer maxProg = (Integer) query.uniqueResult();
if (maxProg != null)
newFunct.setProg(new Integer(maxProg.intValue() + 1));
else
newFunct.setProg(new Integer(1));