Ejemplo n.º 1
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void addRole(final Project project, final String role) {
    ConfigGroup thisProjectConfig = findProjectConfig(project.getRootPath());

    if (thisProjectConfig == null) {
      thisProjectConfig =
          configurationFactory.newConfigGroup(
              ConfigType.PROJECT,
              project.getRootPath().toURI(),
              "Project '" + project.getProjectName() + "' configuration");
      thisProjectConfig.addConfigItem(
          configurationFactory.newConfigItem("security:roles", new ArrayList<String>()));
      configurationService.addConfiguration(thisProjectConfig);
    }

    if (thisProjectConfig != null) {
      final ConfigItem<List> roles = thisProjectConfig.getConfigItem("security:roles");
      roles.getValue().add(role);

      configurationService.updateConfiguration(thisProjectConfig);

    } else {
      throw new IllegalArgumentException("Project " + project.getProjectName() + " not found");
    }
  }
  @Override
  public void removeOrganizationalUnit(String groupName) {
    final ConfigGroup thisGroupConfig = findGroupConfig(groupName);

    if (thisGroupConfig != null) {
      configurationService.removeConfiguration(thisGroupConfig);
      final OrganizationalUnit ou = registeredOrganizationalUnits.remove(groupName);
      removeOrganizationalUnitEvent.fire(new RemoveOrganizationalUnitEvent(ou));
    }
  }
 @PostConstruct
 public void loadOrganizationalUnits() {
   Collection<ConfigGroup> groups =
       configurationService.getConfiguration(ConfigType.ORGANIZATIONAL_UNIT);
   if (groups != null) {
     for (ConfigGroup groupConfig : groups) {
       OrganizationalUnit ou = organizationalUnitFactory.newOrganizationalUnit(groupConfig);
       registeredOrganizationalUnits.put(ou.getName(), ou);
     }
   }
 }
Ejemplo n.º 4
0
 protected ConfigGroup findProjectConfig(final Path projectRoot) {
   final Collection<ConfigGroup> groups =
       configurationService.getConfiguration(ConfigType.PROJECT);
   if (groups != null) {
     for (ConfigGroup groupConfig : groups) {
       if (groupConfig.getName().equals(projectRoot.toURI())) {
         return groupConfig;
       }
     }
   }
   return null;
 }
 protected ConfigGroup findGroupConfig(final String name) {
   final Collection<ConfigGroup> groups =
       configurationService.getConfiguration(ConfigType.ORGANIZATIONAL_UNIT);
   if (groups != null) {
     for (ConfigGroup groupConfig : groups) {
       if (groupConfig.getName().equals(name)) {
         return groupConfig;
       }
     }
   }
   return null;
 }
Ejemplo n.º 6
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void removeRole(final Project project, final String role) {
    final ConfigGroup thisProjectConfig = findProjectConfig(project.getRootPath());

    if (thisProjectConfig != null) {
      final ConfigItem<List> roles = thisProjectConfig.getConfigItem("security:roles");
      roles.getValue().remove(role);

      configurationService.updateConfiguration(thisProjectConfig);

    } else {
      throw new IllegalArgumentException("Project " + project.getProjectName() + " not found");
    }
  }
  @Override
  public void updateOrganizationalUnitOwner(final String name, final String owner) {
    final ConfigGroup thisGroupConfig = findGroupConfig(name);

    if (thisGroupConfig != null) {
      thisGroupConfig.setConfigItem(configurationFactory.newConfigItem("owner", owner));
      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException("OrganizationalUnit " + name + " not found");
    }
  }
  @Override
  public OrganizationalUnit createOrganizationalUnit(final String name, final String owner) {
    final ConfigGroup groupConfig =
        configurationFactory.newConfigGroup(ConfigType.ORGANIZATIONAL_UNIT, name, "");
    groupConfig.addConfigItem(configurationFactory.newConfigItem("owner", owner));
    groupConfig.addConfigItem(
        configurationFactory.newConfigItem("repositories", new ArrayList<String>()));
    groupConfig.addConfigItem(
        configurationFactory.newConfigItem("security:roles", new ArrayList<String>()));
    configurationService.addConfiguration(groupConfig);

    final OrganizationalUnit newOrganizationalUnit =
        organizationalUnitFactory.newOrganizationalUnit(groupConfig);
    registeredOrganizationalUnits.put(newOrganizationalUnit.getName(), newOrganizationalUnit);

    newOrganizationalUnitEvent.fire(new NewOrganizationalUnitEvent(newOrganizationalUnit));

    return newOrganizationalUnit;
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void removeRole(final OrganizationalUnit organizationalUnit, final String role) {
    final ConfigGroup thisGroupConfig = findGroupConfig(organizationalUnit.getName());

    if (thisGroupConfig != null) {
      final ConfigItem<List> roles = thisGroupConfig.getConfigItem("security:roles");
      roles.getValue().remove(role);

      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException(
          "OrganizationalUnit " + organizationalUnit.getName() + " not found");
    }
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public void addRepository(
      final OrganizationalUnit organizationalUnit, final Repository repository) {
    final ConfigGroup thisGroupConfig = findGroupConfig(organizationalUnit.getName());

    if (thisGroupConfig != null) {
      ConfigItem<List> repositories = thisGroupConfig.getConfigItem("repositories");
      repositories.getValue().add(repository.getAlias());

      configurationService.updateConfiguration(thisGroupConfig);

      final OrganizationalUnit updatedOrganizationalUnit =
          organizationalUnitFactory.newOrganizationalUnit(thisGroupConfig);
      registeredOrganizationalUnits.put(
          updatedOrganizationalUnit.getName(), updatedOrganizationalUnit);
    } else {
      throw new IllegalArgumentException(
          "OrganizationalUnit " + organizationalUnit.getName() + " not found");
    }
  }
  public Map<String, WorkDefinition> loadWorkDefinitions() {
    // Find all configured WIDs
    final Map<String, WorkDefinition> workDefinitions = new HashMap<String, WorkDefinition>();
    final List<ConfigGroup> configGroups = configurationService.getConfiguration(ConfigType.EDITOR);
    if (configGroups == null || configGroups.isEmpty()) {
      return workDefinitions;
    }

    // Load configured WIDs
    final List<String> definitions = new ArrayList<String>();
    for (ConfigGroup configGroup : configGroups) {
      if (WorkItemsEditorService.WORK_ITEM_DEFINITION.equals(configGroup.getName())) {
        for (ConfigItem configItem : configGroup.getItems()) {
          definitions.add(configGroup.getConfigItemValue(configItem.getName()));
        }
      }
    }

    // Parse MVEL expressions into model
    workDefinitions.putAll(WorkDefinitionsParser.parse(definitions));

    return workDefinitions;
  }