public void createOrganizationalUnit( final String jobId,
final String organizationalUnitName,
final String organizationalUnitOwner,
final List<String> repositoryNameList ) {
logger.info( "-----JobRequestHelper:createOrganizationalUnit--- , OrganizationalUnit name:" + organizationalUnitName + ", OrganizationalUnit owner:" + organizationalUnitOwner );
JobResult result = new JobResult();
result.setJobId( jobId );
if ( organizationalUnitName == null || organizationalUnitName == null ) {
result.setStatus( JobStatus.BAD_REQUEST );
result.setResult( "OrganizationalUnit name and owner must be provided" );
jobResultEvent.fire( result );
return;
}
OrganizationalUnit organizationalUnit = null;
List<org.uberfire.backend.repositories.Repository> repositories = new ArrayList<org.uberfire.backend.repositories.Repository>();
if ( repositoryNameList != null && repositoryNameList.size() > 0 ) {
for ( String repoName : repositoryNameList ) {
org.uberfire.java.nio.file.Path repositoryPath = getRepositoryRootPath( repoName );
if ( repositoryPath == null ) {
result.setStatus( JobStatus.RESOURCE_NOT_EXIST );
result.setResult( "Repository [" + repoName + "] does not exist" );
jobResultEvent.fire( result );
return;
}
GitRepository repo = new GitRepository( repoName );
repositories.add( repo );
}
organizationalUnit = organizationalUnitService.createOrganizationalUnit( organizationalUnitName,
organizationalUnitOwner,
repositories );
} else {
organizationalUnit = organizationalUnitService.createOrganizationalUnit( organizationalUnitName,
organizationalUnitOwner );
}
if ( organizationalUnit != null ) {
result.setResult( "OrganizationalUnit " + organizationalUnit.getName() + " is created successfully." );
result.setStatus( JobStatus.SUCCESS );
} else {
result.setStatus( JobStatus.FAIL );
}
jobResultEvent.fire( result );
}