Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pathob committed Nov 7, 2023
1 parent 272f667 commit d74c681
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 26 deletions.
73 changes: 73 additions & 0 deletions index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3402,6 +3402,18 @@ endif::internal-generation[]
|
|

| groups
|
| List of <<GroupBean>>
|
|

| users
|
| List of <<UserBean>>
|
|

| schema
|
| DirectoryLdapSchema
Expand Down Expand Up @@ -4205,6 +4217,18 @@ endif::internal-generation[]
|
|

| groups
|
| List of <<GroupBean>>
|
|

| users
|
| List of <<UserBean>>
|
|

|===


Expand Down Expand Up @@ -4515,6 +4539,37 @@ endif::internal-generation[]
|===


[#GroupBean]
=== _GroupBean_



[.fields-GroupBean]
[cols="2,1,2,4,1"]
|===
| Field Name| Required| Type| Description| Format

| name
|
| String
|
|

| description
|
| String
|
|

| active
|
| Boolean
|
|

|===


[#LicenseBean]
=== _LicenseBean_

Expand Down Expand Up @@ -4813,6 +4868,18 @@ endif::internal-generation[]
|
|

| firstName
|
| String
|
|

| lastName
|
| String
|
|

| fullName
|
| String
Expand All @@ -4831,6 +4898,12 @@ endif::internal-generation[]
|
|

| groups
|
| List of <<GroupBean>>
|
|

|===


4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>confapi-crowd-plugin</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<packaging>atlassian-plugin</packaging>

<name>ConfAPI for Crowd</name>
Expand Down Expand Up @@ -66,7 +66,7 @@
<amps.version>8.0.2</amps.version>
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<atlassian.spring.scanner.version>2.1.5</atlassian.spring.scanner.version>
<confapi-commons.version>0.1.1</confapi-commons.version>
<confapi-commons.version>0.2.0-SNAPSHOT</confapi-commons.version>
<plugin.testrunner.version>2.0.1</plugin.testrunner.version>
<!-- Compiler must be 8 so that the plugin can run on Crowd instances using Java 8 -->
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.aservo.confapi.crowd.exception;

import de.aservo.confapi.commons.exception.NotFoundException;
import de.aservo.confapi.commons.model.AbstractDirectoryBean;

public class NotFoundExceptionForDirectory extends NotFoundException {

public NotFoundExceptionForDirectory(
final AbstractDirectoryBean directoryBean) {

this(directoryBean.getName());
}

public NotFoundExceptionForDirectory(
final String name) {

super(String.format("Directory with name '%s' could not be found", name));
}

public NotFoundExceptionForDirectory(
final long id) {

super(String.format("Directory with id '%s' could not be found", id));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.aservo.confapi.crowd.exception;

import de.aservo.confapi.commons.exception.NotFoundException;
import de.aservo.confapi.commons.model.UserBean;

public class NotFoundExceptionForUser extends NotFoundException {

public NotFoundExceptionForUser(
final UserBean userBean) {

this(userBean.getUsername());
}

public NotFoundExceptionForUser(
final String name) {

super(String.format("User with name '%s' could not be found", name));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import de.aservo.confapi.commons.exception.ServiceUnavailableException;
import de.aservo.confapi.commons.model.AbstractDirectoryBean;
import de.aservo.confapi.commons.model.DirectoriesBean;
import de.aservo.confapi.commons.model.DirectoryInternalBean;
import de.aservo.confapi.commons.service.api.DirectoriesService;
import de.aservo.confapi.commons.service.api.UsersService;
import de.aservo.confapi.crowd.model.util.DirectoryBeanUtil;
import org.springframework.stereotype.Component;

Expand All @@ -40,11 +42,16 @@ public class DirectoriesServiceImpl implements DirectoriesService {
@ComponentImport
private final DirectoryManager directoryManager;

@ComponentImport
private final UsersService usersService;

@Inject
public DirectoriesServiceImpl(
final DirectoryManager directoryManager) {
final DirectoryManager directoryManager,
final UsersService usersService) {

this.directoryManager = directoryManager;
this.usersService = usersService;
}

@Override
Expand Down Expand Up @@ -89,11 +96,12 @@ public AbstractDirectoryBean setDirectory(
final boolean testConnection) {

final Directory existingDirectory = findDirectory(id);
final AbstractDirectoryBean resultDirectoryBean;

try {
final Directory mergedDirectory = DirectoryBeanUtil.toDirectory(directoryBean, existingDirectory);
final Directory updatedDirectory = directoryManager.updateDirectory(mergedDirectory);
return DirectoryBeanUtil.toDirectoryInternalBean(updatedDirectory);
resultDirectoryBean = DirectoryBeanUtil.toDirectoryBean(updatedDirectory);
} catch (DirectoryBeanUtil.UnsupportedDirectoryBeanException e) {
throw new BadRequestException(String.format(
"Setting directory type '%s' is not supported (yet)", e.getMessage()));
Expand All @@ -102,23 +110,43 @@ public AbstractDirectoryBean setDirectory(
throw new InternalServerErrorException(String.format(
"When trying to update directory '%s', it could not be found anymore", existingDirectory.getName()));
}

if (DirectoryInternalBean.class.equals(directoryBean.getClass()) && directoryBean.getClass().equals(resultDirectoryBean.getClass())) {
final DirectoryInternalBean directoryInternalBean = (DirectoryInternalBean) directoryBean;
final DirectoryInternalBean resultDirectoryInternalBean = (DirectoryInternalBean) resultDirectoryBean;

resultDirectoryInternalBean.setUsers(usersService.setUsers(directoryInternalBean.getId(), directoryInternalBean.getUsers()));
}

return resultDirectoryBean;
}

@Override
public AbstractDirectoryBean addDirectory(
final @NotNull AbstractDirectoryBean directoryBean,
final boolean testConnection) {

final AbstractDirectoryBean resultDirectoryBean;

try {
final Directory directory = DirectoryBeanUtil.toDirectory(directoryBean);
final Directory addedDirectory = directoryManager.addDirectory(directory);
return DirectoryBeanUtil.toDirectoryBean(addedDirectory);
resultDirectoryBean = DirectoryBeanUtil.toDirectoryBean(addedDirectory);
} catch (DirectoryBeanUtil.UnsupportedDirectoryBeanException e) {
throw new BadRequestException(String.format(
"Adding directory type '%s' is not supported (yet)", e.getMessage()));
} catch (DirectoryInstantiationException e) {
throw new InternalServerErrorException(String.format("Could not create directory '%s'", directoryBean.getName()));
}

if (DirectoryInternalBean.class.equals(directoryBean.getClass()) && directoryBean.getClass().equals(resultDirectoryBean.getClass())) {
final DirectoryInternalBean directoryInternalBean = (DirectoryInternalBean) directoryBean;
final DirectoryInternalBean resultDirectoryInternalBean = (DirectoryInternalBean) resultDirectoryBean;

resultDirectoryInternalBean.setUsers(usersService.setUsers(directoryInternalBean.getId(), directoryInternalBean.getUsers()));
}

return resultDirectoryBean;
}

@Override
Expand Down
Loading

0 comments on commit d74c681

Please sign in to comment.