private void updateModel(CnATreeElement importRootObject, List<CnATreeElement> changedElement) { if (changedElement != null && changedElement.size() > 9) { // if more than 9 elements changed or added do a complete reload CnAElementFactory.getInstance().reloadModelFromDatabase(); } else { if (importRootObject != null) { CnAElementFactory.getModel(importRootObject) .childAdded(importRootObject.getParent(), importRootObject); CnAElementFactory.getModel(importRootObject).databaseChildAdded(importRootObject); if (changedElement != null) { for (CnATreeElement cnATreeElement : changedElement) { CnAElementFactory.getModel(cnATreeElement) .childAdded(cnATreeElement.getParent(), cnATreeElement); CnAElementFactory.getModel(cnATreeElement).databaseChildAdded(cnATreeElement); } } } if (changedElement != null) { for (CnATreeElement cnATreeElement : changedElement) { CnAElementFactory.getModel(cnATreeElement).childChanged(cnATreeElement); CnAElementFactory.getModel(cnATreeElement).databaseChildChanged(cnATreeElement); } } } }
public List<IOOTableRow> getReport(PropertySelection shownColumns) { ArrayList<IOOTableRow> rows = new ArrayList<IOOTableRow>(); AllCategories: for (CnATreeElement category : categories) { ArrayList<IOOTableRow> categoryRows = new ArrayList<IOOTableRow>(); AllItems: for (CnATreeElement child : getItems(category)) { if (child instanceof BausteinUmsetzung) { List<String> columns = shownColumns.get(child.getEntity().getEntityType()); BausteinUmsetzung bst = (BausteinUmsetzung) child; categoryRows.add(new PropertiesRow(child, columns, IOOTableRow.ROW_STYLE_SUBHEADER)); categoryRows.add( new SimpleRow( IOOTableRow.ROW_STYLE_SUBHEADER, "Erreichte Siegelstufe: " + Character.toString(bst.getErreichteSiegelStufe()))); addMassnahmen(shownColumns, categoryRows, bst); } // else: ignore item } // only add if header + items present: if (categoryRows.size() > 1) { rows.add(new SimpleRow(IOOTableRow.ROW_STYLE_HEADER, category.getTitle())); rows.addAll(categoryRows); } } return rows; }
protected void addPermissions(/*not final*/ CnATreeElement element) { HashSet<Permission> newperms = new HashSet<Permission>(); newperms.add(Permission.createPermission(element, authService.getUsername(), true, true)); element.setPermissions(newperms); for (CnATreeElement child : element.getChildren()) { addPermissions(child); } }
public void execute() { IBaseDao<T, Serializable> dao; if (clazz == null) { clazz = CnATypeMapper.getClassFromTypeId(typeId); } dao = (IBaseDao<T, Serializable>) getDaoFactory().getDAO(clazz); IBaseDao<CnATreeElement, Serializable> containerDAO = getDaoFactory().getDAOforTypedElement(container); try { if (!skipReload && !containerDAO.contains(container)) { containerDAO.reload(container, container.getDbId()); } // get constructor with parent-parameter and create new object: if (isOrganization()) { child = (T) Organization.class .getConstructor(CnATreeElement.class, boolean.class) .newInstance(container, createChildren); } else if (isAudit()) { child = (T) Audit.class .getConstructor(CnATreeElement.class, boolean.class) .newInstance(container, createChildren); } else { child = (T) clazz.getConstructor(CnATreeElement.class).newInstance(container); } if (title != null) { // override the default title child.setTitel(title); } if (authService.isPermissionHandlingNeeded()) { addPermissions(containerDAO); } child = dao.merge(child, false); container.addChild(child); child.setParentAndScope(container); if (isOrganization()) { setScope((Organization) child); } // initialize UUID, used to find container in display in views: container.getUuid(); } catch (Exception e) { getLogger().error("Error while creating element", e); throw new RuntimeCommandException(e); } }
private void getStrukturElements(CnATreeElement parent) { for (CnATreeElement child : parent.getChildren()) { if (!(child instanceof IDatenschutzElement)) { items.add(child); if (!categories.contains(child.getParent())) { categories.add(child.getParent()); } } getStrukturElements(child); } }
/* (non-Javadoc) * @see sernet.gs.ui.rcp.main.common.model.CnATreeElement#canContain(java.lang.Object) */ @Override public boolean canContain(Object obj) { boolean canContain = false; if (obj instanceof CnATreeElement) { CnATreeElement element = (CnATreeElement) obj; canContain = Arrays.asList(getChildTypes()).contains(element.getTypeId()) || this.getTypeId().equals(element.getTypeId()); } return canContain; }
/** @param exportThread */ private void getValuesFromThread(final ExportThread exportThread) { linkSet.addAll(exportThread.getLinkSet()); attachmentSet.addAll(exportThread.getAttachmentSet()); exportedEntityTypes.addAll(exportThread.getExportedEntityTypes()); exportedTypes.addAll(exportThread.getExportedTypes()); changedElements.addAll(exportThread.getChangedElementList()); final CnATreeElement element = getElementFromThread(exportThread); if (element != null && FinishedRiskAnalysis.TYPE_ID.equals(element.getTypeId())) { riskAnalysisIdSet.add(element.getDbId()); } }
protected List<CnATreeElement> getItems(CnATreeElement category) { if (items == null) { getItems(); } ArrayList<CnATreeElement> categoryItems = new ArrayList<CnATreeElement>(); for (CnATreeElement item : items) { if (item.getParent().equals(category)) { categoryItems.add(item); } } return categoryItems; }
/** * Creates an ext-id for a tree-element * * @param element a tree-element * @return ext-id for the tree-element */ public static String createExtId(CnATreeElement element) { if (element == null) { return null; } String extId = element.getExtId(); if (extId == null || extId.isEmpty()) { if (element.getEntity() != null) { extId = element.getEntity().getId(); } else { extId = element.getId(); } } return extId; }
private Map<String, CnATreeElement> loadChildrenTitleMap( String uuidParent, Map<String, CnATreeElement> map) { RetrieveInfo ri = RetrieveInfo.getChildrenInstance().setChildrenProperties(true); ControlGroup source = getDao().findByUuid(uuidParent, ri); if (source != null) { for (CnATreeElement element : source.getChildren()) { if (element instanceof IISO27kGroup) { map = loadChildrenTitleMap(element.getUuid(), map); } else { map.put(getNumberOrTitle(element.getTitle()), element); } } } return map; }
private void exportChildren(final ExportTransaction transaction) throws CommandException { final int timeOutFactor = 40; final CnATreeElement element = transaction.getElement(); final Set<CnATreeElement> children = element.getChildren(); if (FinishedRiskAnalysis.TYPE_ID.equals(element.getTypeId())) { children.addAll(getRiskAnalysisOrphanElements(element)); } final List<ExportTransaction> transactionList = new ArrayList<ExportTransaction>(); taskExecutor = Executors.newFixedThreadPool(getMaxNumberOfThreads()); if (!children.isEmpty()) { for (final CnATreeElement child : children) { final ExportTransaction childTransaction = new ExportTransaction(child); transactionList.add(childTransaction); final ExportThread thread = new ExportThread(childTransaction); configureThread(thread); // Multi thread: thread.addListener( new IThreadCompleteListener() { @Override public void notifyOfThreadComplete(final Thread thread) { final ExportThread exportThread = (ExportThread) thread; synchronized (LOCK) { if (exportThread.getSyncObject() != null) { transaction.getTarget().getChildren().add(exportThread.getSyncObject()); } getValuesFromThread(exportThread); } } }); taskExecutor.execute(thread); } } awaitTermination(transactionList.size() * timeOutFactor); if (getLog().isDebugEnabled() && transactionList.size() > 0) { getLog().debug(transactionList.size() + " export threads finished."); } for (final ExportTransaction childTransaction : transactionList) { if (checkElement(childTransaction.getElement())) { exportChildren(childTransaction); } } }
private CnATreeElement getFromCache(CnATreeElement element) { final Element cachedElement = getCache().get(element.getUuid()); if (cachedElement != null) { element = (CnATreeElement) cachedElement.getValue(); if (getLog().isDebugEnabled()) { getLog() .debug("Element from cache: " + element.getTitle() + ", UUID: " + element.getUuid()); } } else { element = getDao().retrieve(element.getDbId(), RetrieveInfo.getPropertyInstance()); if (element != null) { getCache().put(new Element(element.getUuid(), element)); } } return element; }
private Set<CnATreeElement> getRiskAnalysisOrphanElements(final CnATreeElement element) throws CommandException { final Set<CnATreeElement> returnValue = new HashSet<CnATreeElement>(); FindRiskAnalysisListsByParentID loader = new FindRiskAnalysisListsByParentID(element.getDbId()); loader = getCommandService().executeCommand(loader); returnValue.addAll(loader.getFoundLists().getAssociatedGefaehrdungen()); return returnValue; }
private void addPermissions(IBaseDao<CnATreeElement, Serializable> containerDAO) { // By default, inherit permissions from parent element but ITVerbund // instances cannot do this, as its parents (BSIModel) is not visible // and has no permissions. Therefore we use the name of the currently // logged in user as a role which has read and write permissions for // the new ITVerbund. if (child instanceof ITVerbund || child instanceof Organization || (child instanceof Audit && !isInheritAuditPermissions())) { addPermissions(child); } else { RetrieveInfo ri = new RetrieveInfo(); ri.setPermissions(true); CnATreeElement elementPerm = containerDAO.retrieve(container.getDbId(), ri); child.setPermissions(Permission.clonePermissionSet(child, elementPerm.getPermissions())); } }
/** * @param shell * @param reportScope */ public GenerateReportDialog(Shell shell, Object reportScope) { this(shell); if (reportScope instanceof Audit) { this.useCase = IReportType.USE_CASE_ID_AUDIT_REPORT; } else if (reportScope instanceof Organization || reportScope instanceof ITVerbund) { this.useCase = IReportType.USE_CASE_ID_GENERAL_REPORT; } else { this.useCase = IReportType.USE_CASE_ID_ALWAYS_REPORT; } CnATreeElement cnaElmt = (CnATreeElement) reportScope; this.auditId = cnaElmt.getDbId(); this.auditName = cnaElmt.getTitle(); if (LOG.isDebugEnabled()) { LOG.debug("Setting audit in report dialog: " + auditId); // $NON-NLS-1$ } }
/** Load list of scopes for user selection of top level element for report. */ private void setupComboScopes() { // check if audit was selected by context menu: if (this.auditId != null && isContextMenuCall()) { scopeCombo.removeAll(); scopeCombo.add(this.auditName); rootElement = auditId; scopeCombo.setEnabled(true); scopeCombo.select(0); scopeCombo.redraw(); return; } else if (this.preSelectedElments != null && this.preSelectedElments.size() > 0 && isContextMenuCall()) { scopeCombo.removeAll(); ArrayList<Integer> auditIDList = new ArrayList<Integer>(); StringBuilder sb = new StringBuilder(); for (CnATreeElement elmt : preSelectedElments) { sb.append(elmt.getTitle()); if (preSelectedElments.indexOf(elmt) != preSelectedElments.size() - 1) sb.append(" & "); auditIDList.add(elmt.getDbId()); } scopeCombo.add(sb.toString()); rootElements = auditIDList.toArray(new Integer[auditIDList.size()]); scopeCombo.setEnabled(false); scopeCombo.select(0); scopeCombo.redraw(); return; } scopes = new ArrayList<CnATreeElement>(); scopeTitles = new ArrayList<String>(); scopes.addAll(loadScopes()); scopes.addAll(loadITVerbuende()); Collections.sort( scopes, new Comparator<CnATreeElement>() { @Override public int compare(CnATreeElement o1, CnATreeElement o2) { return o1.getTitle().compareToIgnoreCase(o2.getTitle()); } }); for (CnATreeElement elmt : scopes) { scopeTitles.add(elmt.getTitle()); if (LOG.isDebugEnabled()) { LOG.debug( Messages.GenerateReportDialog_16 + elmt.getDbId() + ": " + elmt .getTitle()); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-1$ // //$NON-NLS-1$ } } String[] titles = scopeTitles.toArray(new String[scopeTitles.size()]); scopeCombo.setItems(titles); }
/* (non-Javadoc) * @see sernet.verinice.interfaces.ICommand#execute() */ @SuppressWarnings("restriction") @Override public void execute() { IBaseDao<Configuration, Serializable> confDao = getDaoFactory().getDAO(Configuration.class); List<Configuration> confs = confDao.findAll(); for (Configuration c : confs) { try { CnATreeElement elmt = (CnATreeElement) c.getPerson(); if (elmt.getUuid().equals(pIso.getUuid())) { configuration = c; break; } } catch (Exception e) { LOG.error("Error", e); } } }
/** * This method is saving the entity of a CnaTreeElement but not the CnaTreeElement itself. * * <p>After saving the entity business impact inheritance is started by calling fireChange. * * @see * sernet.verinice.interfaces.IElementEntityDao#mergeEntityOfElement(sernet.verinice.model.common.CnATreeElement, * boolean) */ public CnATreeElement mergeEntityOfElement(CnATreeElement element, boolean fireChange) { if (LOG_INHERIT.isDebug()) { LOG_INHERIT.debug("mergeEntityOfElement"); } Entity entity = element.getEntity(); entity = super.merge(entity); element.setEntity(entity); if (!getHibernateTemplate().contains(element)) { getHibernateTemplate().load(element, element.getDbId()); } if (fireChange) { fireChange(element); } index(element); return element; }
private List<UnifyMapping> createMapping( Map<String, CnATreeElement> sourceMap, Map<String, CnATreeElement> destinationMap) { List<UnifyMapping> mappings = new ArrayList<UnifyMapping>(sourceMap.size()); for (String title : sourceMap.keySet()) { CnATreeElement source = sourceMap.get(title); UnifyMapping mapping = new UnifyMapping(new UnifyElement(source.getUuid(), source.getTitle())); CnATreeElement destination = destinationMap.get(title); if (destination != null) { mapping.setDestinationElement( new UnifyElement(destination.getUuid(), destination.getTitle())); } mappings.add(mapping); } return mappings; }
@Override protected Set<CnATreeElement> getObjectsForLeftElement(CnATreeElement assetGroup) { if (LOG.isDebugEnabled()) { LOG.debug("Loading objects for asset group: " + assetGroup.getTitle()); } Set<CnATreeElement> elements = new HashSet<CnATreeElement>(); elements.add(assetGroup); elements.addAll(getGraph().getLinkTargets(assetGroup, Edge.RELATIVES)); Set<CnATreeElement> scenarios = new HashSet<CnATreeElement>(); for (CnATreeElement asset : elements) { scenarios.addAll(getGraph().getLinkTargets(asset, IncidentScenario.REL_INCSCEN_ASSET)); } Set<CnATreeElement> controls = new HashSet<CnATreeElement>(); for (CnATreeElement scen : scenarios) { controls.addAll(getGraph().getLinkTargets(scen, Control.REL_CONTROL_INCSCEN)); } elements.addAll(scenarios); elements.addAll(controls); return elements; }
/** @param baustein */ private void initParent(/* not final */ BausteinUmsetzung baustein) { CnATreeElement withParent = Retriever.checkRetrieveParent(baustein); CnATreeElement parent = Retriever.checkRetrieveElement(withParent.getParent()); baustein.setParent(parent); }
/** @param child2 */ private void setScope(Organization org) { org.setScopeId(org.getDbId()); for (CnATreeElement child : org.getChildren()) { child.setScopeId(org.getDbId()); } }
private boolean checkElement(final CnATreeElement element) { return (getEntityTypesBlackList() == null || getEntityTypesBlackList().get(element.getTypeId()) == null) && (getEntityClassBlackList() == null || getEntityClassBlackList().get(element.getClass()) == null); }