Skip to content

Commit 627449e

Browse files
committed
ADD active object
1 parent 167235b commit 627449e

File tree

10 files changed

+183
-7
lines changed

10 files changed

+183
-7
lines changed

README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ Useful resources:
2020
* [SAL 3.0 Upgrade Guide](https://developer.atlassian.com/server/framework/atlassian-sdk/sal-3-0-upgrade-guide/)
2121
* [Atlassian Community - REST requests from a custom plugin](https://community.atlassian.com/t5/Answers-Developer-Questions/What-is-the-recommended-way-to-send-REST-requests-from-a-custom/qaq-p/568227)
2222
* [Atlassian AUI - Soy template components](https://bitbucket.org/atlassian/aui/src/6a8e37f85a07952cc290503f54d85ff5bebc8783/src/soy/?at=5.10.x)
23+
24+
Code samples:
25+
26+
* https://bitbucket.org/atlassian/bitbucket-code-coverage/src/master/code-coverage-plugin/

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
<artifactId>bitbucket-spi</artifactId>
5757
<scope>provided</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>com.atlassian.activeobjects</groupId>
61+
<artifactId>activeobjects-plugin</artifactId>
62+
<scope>provided</scope>
63+
</dependency>
5964
<dependency>
6065
<groupId>com.atlassian.soy</groupId>
6166
<artifactId>soy-template-renderer-api</artifactId>
@@ -82,6 +87,17 @@
8287
<scope>provided</scope>
8388
</dependency>
8489

90+
<dependency>
91+
<groupId>org.springframework</groupId>
92+
<artifactId>spring-beans</artifactId>
93+
<scope>provided</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.springframework</groupId>
97+
<artifactId>spring-context</artifactId>
98+
<scope>provided</scope>
99+
</dependency>
100+
85101
<dependency>
86102
<groupId>com.atlassian.plugin</groupId>
87103
<artifactId>atlassian-spring-scanner-annotation</artifactId>

src/main/java/com/recuencojones/bitbucket/log/RepositoryCloneSettingsServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import java.util.Map;
3131

32-
class RepositoryCloneSettingsServlet extends HttpServlet {
32+
public class RepositoryCloneSettingsServlet extends HttpServlet {
3333
private static final Logger log = LoggerFactory.getLogger(RepositoryCloneSettingsServlet.class);
3434

3535
@ComponentImport
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.recuencojones.bitbucket.log.dao;
2+
3+
import net.java.ao.Accessor;
4+
import net.java.ao.Entity;
5+
import net.java.ao.Mutator;
6+
import net.java.ao.schema.Indexed;
7+
import net.java.ao.schema.NotNull;
8+
import net.java.ao.schema.StringLength;
9+
import net.java.ao.schema.Table;
10+
11+
import static net.java.ao.schema.StringLength.UNLIMITED;
12+
13+
@Table("RC_SETTINGS")
14+
public interface RepositoryCloneSettings extends Entity {
15+
16+
String REPO_ID_COLUMN = "REPO_ID";
17+
String URL_COLUMN = "URL";
18+
19+
@Indexed
20+
@Accessor(REPO_ID_COLUMN)
21+
@NotNull
22+
int getId();
23+
24+
@Accessor(URL_COLUMN)
25+
@StringLength(UNLIMITED)
26+
String getURL();
27+
28+
@Mutator(URL_COLUMN)
29+
void setURL(String url);
30+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.recuencojones.bitbucket.log.dao;
2+
3+
import com.atlassian.activeobjects.external.ActiveObjects;
4+
5+
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
6+
import org.springframework.stereotype.Component;
7+
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import net.java.ao.DBParam;
12+
13+
import javax.inject.Inject;
14+
import javax.inject.Named;
15+
16+
import static com.recuencojones.bitbucket.log.dao.RepositoryCloneSettings.REPO_ID_COLUMN;
17+
18+
@Named
19+
@Component
20+
public class RepositoryCloneSettingsDAO {
21+
private static final String ID_QUERY = String.format("%s = ?", REPO_ID_COLUMN);
22+
23+
@ComponentImport
24+
private final ActiveObjects ao;
25+
26+
@Inject
27+
public RepositoryCloneSettingsDAO(
28+
ActiveObjects ao
29+
) {
30+
this.ao = ao;
31+
}
32+
33+
public RepositoryCloneSettings save(int repositoryID, String url) {
34+
RepositoryCloneSettings settings = find(repositoryID);
35+
36+
if (settings == null) {
37+
settings = ao.create(
38+
RepositoryCloneSettings.class,
39+
new DBParam(REPO_ID_COLUMN, repositoryID)
40+
);
41+
}
42+
43+
settings.setURL(url);
44+
settings.save();
45+
46+
return settings;
47+
}
48+
49+
public RepositoryCloneSettings get(int repositoryID) {
50+
return find(repositoryID);
51+
}
52+
53+
public void remove(int repositoryID) {
54+
RepositoryCloneSettings settings = find(repositoryID);
55+
56+
ao.delete(settings);
57+
}
58+
59+
private RepositoryCloneSettings find(int repositoryID) {
60+
RepositoryCloneSettings[] results = ao.find(RepositoryCloneSettings.class, ID_QUERY, repositoryID);
61+
62+
if (results.length == 0) {
63+
return null;
64+
}
65+
66+
return results[0];
67+
}
68+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.recuencojones.bitbucket.log.rest;
2+
3+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4+
import org.codehaus.jackson.annotate.JsonProperty;
5+
6+
import java.util.List;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class RepositoryCloneSettingsDTO {
10+
11+
@JsonProperty("url")
12+
private String url;
13+
14+
public String getURL() {
15+
return url;
16+
}
17+
18+
public void setURL(String url) {
19+
this.url = url;
20+
}
21+
}

src/main/java/com/recuencojones/bitbucket/log/rest/RepositoryCloneSettingsResource.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.recuencojones.bitbucket.log.rest;
22

3+
import com.recuencojones.bitbucket.log.rest.*;
4+
import com.recuencojones.bitbucket.log.dao.*;
5+
36
import com.atlassian.bitbucket.repository.Repository;
47
import com.atlassian.bitbucket.rest.util.ResourcePatterns;
58
import com.atlassian.bitbucket.rest.util.ResponseFactory;
@@ -34,26 +37,40 @@ public class RepositoryCloneSettingsResource {
3437
@ComponentImport
3538
private final PermissionValidationService permissionValidationService;
3639

40+
private final RepositoryCloneSettingsDAO repositoryCloneSettingsDAO;
41+
3742
@Inject
3843
public RepositoryCloneSettingsResource(
39-
PermissionValidationService permissionValidationService
44+
PermissionValidationService permissionValidationService,
45+
RepositoryCloneSettingsDAO repositoryCloneSettingsDAO
4046
) {
4147
this.permissionValidationService = permissionValidationService;
48+
this.repositoryCloneSettingsDAO = repositoryCloneSettingsDAO;
4249
}
4350

4451
@GET
4552
public Response getSettings(@Context Repository repository) {
4653
log.info("Retrieve logging url for repository {}/{}", repository.getProject().getKey(), repository.getSlug());
4754

48-
// return ResponseFactory.ok(new RestAutoUnapproveSettings(unapproveService.getSettings(scope))).build();
55+
RepositoryCloneSettings settings = repositoryCloneSettingsDAO.get(repository.getId());
56+
57+
if (settings != null) {
58+
RepositoryCloneSettingsDTO settingsDTO = new RepositoryCloneSettingsDTO();
59+
60+
settingsDTO.setURL(settings.getURL());
61+
62+
return ResponseFactory.ok(settingsDTO).build();
63+
}
64+
4965
return ResponseFactory.ok().build();
5066
}
5167

5268
@POST
53-
public Response saveSettings(@Context Repository repository) {
69+
public Response saveSettings(@Context Repository repository, RepositoryCloneSettingsDTO settings) {
5470
permissionValidationService.validateForRepository(repository, Permission.REPO_ADMIN);
5571

5672
log.info("Store logging url for repository {}/{}", repository.getProject().getKey(), repository.getSlug());
73+
repositoryCloneSettingsDAO.save(repository.getId(), settings.getURL());
5774

5875
return ResponseFactory.ok().build();
5976
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:osgi="http://www.springframework.org/schema/osgi"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7+
http://www.springframework.org/schema/osgi
8+
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
9+
10+
<osgi:reference id="activeObjects" interface="com.atlassian.activeobjects.external.ActiveObjects"/>
11+
12+
</beans>

src/main/resources/atlassian-plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<package>com.recuencojones.bitbucket.log.rest</package>
3232
</rest>
3333

34+
<ao key="ao-module">
35+
<description>The module configuring the Active Objects service used by this plugin</description>
36+
<entity>com.recuencojones.bitbucket.log.dao.RepositoryCloneSettings</entity>
37+
</ao>
38+
3439
<client-resource key="log-on-clone-serverside-resources">
3540
<directory location="/static/">
3641
<include>/**/*.soy</include>

src/main/resources/static/clone-log-settings.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,18 @@ define('plugin/log-on-clone/repository-settings', [
8484
url: resourceUrl('settings'),
8585
type: 'GET'
8686
})
87-
.then(function() {
87+
.then(function(response) {
88+
if (response) {
89+
setValue(response.url);
90+
}
91+
8892
setInputEnabled(true);
8993
setSubmitEnabled(true);
90-
setValue('https://en6qhxx7a3ksl.x.pipedream.net');
9194
});
9295
}
9396

9497
exports.onReady = function() {
95-
$(document).ready(() => {
98+
$(document).ready(function() {
9699
init();
97100
});
98101
};

0 commit comments

Comments
 (0)