-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement applications endpoint #16
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/main/java/de/aservo/confapi/crowd/model/ApplicationBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.aservo.confapi.crowd.model; | ||
|
||
import de.aservo.confapi.commons.constants.ConfAPI; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@XmlRootElement(name = ConfAPI.APPLICATION) | ||
public class ApplicationBean { | ||
|
||
public enum ApplicationType { | ||
GENERIC, | ||
PLUGIN, | ||
CROWD, | ||
JIRA, | ||
CONFLUENCE, | ||
BITBUCKET, | ||
FISHEYE, | ||
CRUCIBLE, | ||
BAMBOO, | ||
; | ||
} | ||
|
||
@XmlElement | ||
private Long id; | ||
|
||
@XmlElement | ||
private String name; | ||
|
||
@XmlElement | ||
private String description; | ||
|
||
@XmlElement | ||
private Boolean active; | ||
|
||
@XmlElement | ||
private ApplicationType type; | ||
|
||
@XmlElement | ||
private String password; | ||
|
||
public static final ApplicationBean EXAMPLE_1; | ||
public static final ApplicationBean EXAMPLE_2; | ||
|
||
static { | ||
EXAMPLE_1 = new ApplicationBean(); | ||
EXAMPLE_1.setName("app_name"); | ||
EXAMPLE_1.setDescription("app_description"); | ||
EXAMPLE_1.setActive(true); | ||
EXAMPLE_1.setPassword("3x4mpl3"); | ||
EXAMPLE_1.setType(ApplicationType.GENERIC); | ||
EXAMPLE_1.setId(1L); | ||
} | ||
|
||
static { | ||
EXAMPLE_2 = new ApplicationBean(); | ||
EXAMPLE_2.setName("app_name2"); | ||
EXAMPLE_2.setDescription("app_description2"); | ||
EXAMPLE_2.setActive(false); | ||
EXAMPLE_2.setPassword("3x4mpl32"); | ||
EXAMPLE_2.setType(ApplicationType.BAMBOO); | ||
EXAMPLE_1.setId(2L); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/de/aservo/confapi/crowd/model/ApplicationsBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.aservo.confapi.crowd.model; | ||
|
||
import de.aservo.confapi.commons.constants.ConfAPI; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.Collection; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@XmlRootElement(name = ConfAPI.APPLICATIONS) | ||
public class ApplicationsBean { | ||
|
||
@XmlElement | ||
private Collection<ApplicationBean> applications; | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/de/aservo/confapi/crowd/model/util/ApplicationBeanUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package de.aservo.confapi.crowd.model.util; | ||
|
||
import com.atlassian.crowd.embedded.api.PasswordCredential; | ||
import com.atlassian.crowd.model.application.Application; | ||
import com.atlassian.crowd.model.application.ApplicationType; | ||
import com.atlassian.crowd.model.application.ImmutableApplication; | ||
import de.aservo.confapi.crowd.model.ApplicationBean; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class ApplicationBeanUtil { | ||
|
||
public static ApplicationBean toApplicationBean( | ||
final Application application) { | ||
|
||
final ApplicationBean applicationBean = new ApplicationBean(); | ||
|
||
applicationBean.setId(application.getId()); | ||
applicationBean.setName(application.getName()); | ||
applicationBean.setDescription(application.getDescription()); | ||
applicationBean.setActive(application.isActive()); | ||
applicationBean.setType(toApplicationBeanType(application.getType())); | ||
|
||
return applicationBean; | ||
} | ||
|
||
public static Application toApplication( | ||
final ApplicationBean applicationBean) { | ||
|
||
// don't set id from request data | ||
return ImmutableApplication.builder(applicationBean.getName(), toApplicationType(applicationBean.getType())) | ||
.setDescription(applicationBean.getDescription()) | ||
.setActive(applicationBean.getActive()) | ||
.setPasswordCredential(PasswordCredential.unencrypted(applicationBean.getPassword())) | ||
.build(); | ||
} | ||
|
||
@Nullable | ||
public static ApplicationBean.ApplicationType toApplicationBeanType( | ||
final ApplicationType applicationType) { | ||
|
||
if (ApplicationType.GENERIC_APPLICATION.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.GENERIC; | ||
} else if (ApplicationType.PLUGIN.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.PLUGIN; | ||
} else if (ApplicationType.CROWD.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.CROWD; | ||
} else if (ApplicationType.JIRA.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.JIRA; | ||
} else if (ApplicationType.CONFLUENCE.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.CONFLUENCE; | ||
} else if (ApplicationType.STASH.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.BITBUCKET; | ||
} else if (ApplicationType.FISHEYE.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.FISHEYE; | ||
} else if (ApplicationType.CRUCIBLE.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.CRUCIBLE; | ||
} else if (ApplicationType.BAMBOO.equals(applicationType)) { | ||
return ApplicationBean.ApplicationType.BAMBOO; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Nullable | ||
public static ApplicationType toApplicationType( | ||
final ApplicationBean.ApplicationType applicationBeanType) { | ||
|
||
if (ApplicationBean.ApplicationType.GENERIC.equals(applicationBeanType)) { | ||
return ApplicationType.GENERIC_APPLICATION; | ||
} else if (ApplicationBean.ApplicationType.PLUGIN.equals(applicationBeanType)) { | ||
return ApplicationType.PLUGIN; | ||
} else if (ApplicationBean.ApplicationType.CROWD.equals(applicationBeanType)) { | ||
return ApplicationType.CROWD; | ||
} else if (ApplicationBean.ApplicationType.JIRA.equals(applicationBeanType)) { | ||
return ApplicationType.JIRA; | ||
} else if (ApplicationBean.ApplicationType.CONFLUENCE.equals(applicationBeanType)) { | ||
return ApplicationType.CONFLUENCE; | ||
} else if (ApplicationBean.ApplicationType.BITBUCKET.equals(applicationBeanType)) { | ||
return ApplicationType.STASH; | ||
} else if (ApplicationBean.ApplicationType.FISHEYE.equals(applicationBeanType)) { | ||
return ApplicationType.FISHEYE; | ||
} else if (ApplicationBean.ApplicationType.CRUCIBLE.equals(applicationBeanType)) { | ||
return ApplicationType.CRUCIBLE; | ||
} else if (ApplicationBean.ApplicationType.BAMBOO.equals(applicationBeanType)) { | ||
return ApplicationType.BAMBOO; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private ApplicationBeanUtil() { | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/de/aservo/confapi/crowd/rest/ApplicationsResourceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.aservo.confapi.crowd.rest; | ||
|
||
import com.sun.jersey.spi.container.ResourceFilters; | ||
import de.aservo.confapi.commons.constants.ConfAPI; | ||
import de.aservo.confapi.crowd.filter.SysadminOnlyResourceFilter; | ||
import de.aservo.confapi.crowd.model.ApplicationBean; | ||
import de.aservo.confapi.crowd.model.ApplicationsBean; | ||
import de.aservo.confapi.crowd.rest.api.ApplicationsResource; | ||
import de.aservo.confapi.crowd.service.api.ApplicationsService; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path(ConfAPI.APPLICATIONS) | ||
@ResourceFilters(SysadminOnlyResourceFilter.class) | ||
@Component | ||
public class ApplicationsResourceImpl implements ApplicationsResource { | ||
|
||
private final ApplicationsService applicationsService; | ||
|
||
@Inject | ||
public ApplicationsResourceImpl( | ||
final ApplicationsService applicationsService) { | ||
|
||
this.applicationsService = applicationsService; | ||
} | ||
|
||
@Override | ||
public Response getApplications() { | ||
return Response.ok(applicationsService.getApplications()).build(); | ||
} | ||
pathob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
public Response getApplication( | ||
final long id) { | ||
return Response.ok(applicationsService.getApplication(id)).build(); | ||
} | ||
|
||
@Override | ||
public Response setApplications( | ||
final ApplicationsBean applicationsBean) { | ||
return Response.ok(applicationsService.setApplications(applicationsBean)).build(); | ||
} | ||
|
||
@Override | ||
public Response setApplication( | ||
final long id, | ||
final ApplicationBean applicationBean) { | ||
return Response.ok(applicationsService.setApplication(id, applicationBean)).build(); | ||
} | ||
|
||
@Override | ||
public Response addApplication( | ||
final ApplicationBean applicationBean) { | ||
return Response.ok(applicationsService.addApplication(applicationBean)).build(); | ||
} | ||
|
||
@Override | ||
public Response deleteApplications(boolean force) { | ||
applicationsService.deleteApplications(force); | ||
return Response.ok().build(); | ||
} | ||
|
||
@Override | ||
public Response deleteApplication(long id) { | ||
applicationsService.deleteApplication(id); | ||
return Response.ok().build(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Da sich die gesamte Application Prodzedur eh nur in Crowd abspielt (und nicht in der commons, wo wir ja atlassian-free bleiben wollen), hätte man doch gleich Atlassian's
ApplicationType
anstelle vonApplicationBean.ApplicationType
in die Bean aufnehmen können oder?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prinzipiell schon, aber so behalten wir die Kontrolle und Bitbucket darf an unseren Endpoints Bitbucket heißen und nicht Stash.