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 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;
  }
  @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");
    }
  }