/** 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);
  }
Beispiel #2
0
 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;
 }
  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);
    }
  }
Beispiel #4
0
 /** @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());
   }
 }
Beispiel #5
0
 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;
 }
  /**
   * @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$
    }
  }
 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()));
   }
 }
  /**
   * 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;
  }