class OrganizationalUnitFactoryImpl implements OrganizationalUnitFactory {

    @Override
    public OrganizationalUnit newOrganizationalUnit(final SpaceInfo spaceInfo) {

        OrganizationalUnitImpl organizationalUnit = new OrganizationalUnitImpl(spaceInfo.getName(),
                                                                               spaceInfo.getDefaultGroupId());
        organizationalUnit.setDescription(spaceInfo.getDescription());

        final List<RepositoryInfo> repositories = spaceInfo.getRepositories();
        if (repositories != null) {
            for (RepositoryInfo alias : repositories) {
                Space space = spacesAPI.getSpace(organizationalUnit.getName());
                final Repository repo = repositoryService.getRepositoryFromSpace(space,
                                                                                 alias.getName());
                if (repo != null) {
                    organizationalUnit.getRepositories().add(repo);
                }
            }
        }

        final List<String> securityGroups = spaceInfo.getSecurityGroups();
        if (securityGroups != null) {
            organizationalUnit.getGroups().addAll(securityGroups);
        }

        final Collection<Contributor> contributors = spaceInfo.getContributors();
        if (contributors != null) {
            organizationalUnit.getContributors().addAll(contributors);
        }

        return organizationalUnit;
    }

    @Inject public  OrganizationalUnitFactoryImpl(final RepositoryService repositoryService,
                                         final SpacesAPI spacesAPI);

}