Skip to content

Commit a9d0f31

Browse files
authored
Merge pull request #299 from FlowCI/develop
Develop
2 parents ef4f464 + 339015a commit a9d0f31

File tree

56 files changed

+2050
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2050
-45
lines changed

docker/app-api.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ hibernate.hbm2ddl.auto = validate
1616
api.workspace = ${HOME}/flow-ci/workspace
1717
api.git.cache = ${HOME}/flow-ci/git-cache
1818
api.git.workspace = ${HOME}/flow-ci/git-repos
19+
api.local_file_resource.workspace = ${HOME}/flow-ci/local_file_resources
20+
1921
api.zone.default = default
2022

2123
### expiration duration of token, it's in millisecond ###

platform-api/src/main/java/com/flow/platform/api/config/WebConfig.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.flow.platform.api.config;
1818

19+
import com.flow.platform.api.multipart.FlowMultipartMatcher;
20+
import com.flow.platform.api.multipart.FlowMultipartResolver;
1921
import com.flow.platform.api.resource.PropertyResourceLoader;
2022
import com.flow.platform.api.security.AuthenticationInterceptor;
2123
import com.flow.platform.api.security.OptionsInterceptor;
@@ -47,7 +49,6 @@
4749
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
4850
import org.springframework.security.web.util.matcher.RequestMatcher;
4951
import org.springframework.web.multipart.MultipartResolver;
50-
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
5152
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5253
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
5354
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -76,6 +77,8 @@ public class WebConfig extends WebMvcConfigurerAdapter {
7677

7778
private final static int MAX_UPLOAD_SIZE = 2 * 1024 * 1024;
7879

80+
private final static int LOCAL_FILE_RESOURCE_MAX_UPLOAD_SIZE = 500 * 1024 * 1024;
81+
7982
private final RawGsonMessageConverter jsonConverter =
8083
new RawGsonMessageConverter(true, GSON_CONFIG_FOR_RESPONSE, Jsonable.GSON_CONFIG);
8184

@@ -100,8 +103,12 @@ public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer
100103

101104
@Bean(name = "multipartResolver")
102105
public MultipartResolver multipartResolver() throws IOException {
103-
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
104-
resolver.setMaxUploadSize(MAX_UPLOAD_SIZE);
106+
List<FlowMultipartMatcher> matchers = ImmutableList.of(
107+
new FlowMultipartMatcher("/credentials", MAX_UPLOAD_SIZE),
108+
new FlowMultipartMatcher("/local_file_resources", LOCAL_FILE_RESOURCE_MAX_UPLOAD_SIZE)
109+
);
110+
111+
FlowMultipartResolver resolver = new FlowMultipartResolver(matchers);
105112
return resolver;
106113
}
107114

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.flow.platform.api.controller;
18+
19+
import com.flow.platform.api.domain.Artifact;
20+
import com.flow.platform.api.service.ArtifactService;
21+
import java.math.BigInteger;
22+
import java.util.List;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.web.bind.annotation.GetMapping;
25+
import org.springframework.web.bind.annotation.PostMapping;
26+
import org.springframework.web.bind.annotation.RequestBody;
27+
import org.springframework.web.bind.annotation.RequestMapping;
28+
import org.springframework.web.bind.annotation.RequestParam;
29+
import org.springframework.web.bind.annotation.RestController;
30+
31+
/**
32+
* @author yh@firim
33+
*/
34+
@RestController
35+
@RequestMapping(path = "/artifacts")
36+
public class ArtifactController {
37+
38+
@Autowired
39+
private ArtifactService artifactService;
40+
41+
@PostMapping
42+
public Artifact create(@RequestBody Artifact artifact){
43+
return artifactService.create(artifact);
44+
}
45+
46+
@GetMapping
47+
public List<Artifact> index(@RequestParam BigInteger jobId) {
48+
return artifactService.list(jobId);
49+
}
50+
51+
}

platform-api/src/main/java/com/flow/platform/api/controller/JobController.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@
1616

1717
package com.flow.platform.api.controller;
1818

19+
import com.flow.platform.api.domain.Artifact;
1920
import com.flow.platform.api.domain.SearchCondition;
2021
import com.flow.platform.api.domain.job.Job;
2122
import com.flow.platform.api.domain.job.JobCategory;
2223
import com.flow.platform.api.domain.job.NodeResult;
2324
import com.flow.platform.api.domain.permission.Actions;
2425
import com.flow.platform.api.domain.user.User;
2526
import com.flow.platform.api.security.WebSecurity;
27+
import com.flow.platform.api.service.ArtifactService;
2628
import com.flow.platform.api.service.LogService;
2729
import com.flow.platform.api.service.job.JobSearchService;
2830
import com.flow.platform.api.service.job.JobService;
2931
import com.flow.platform.api.service.job.NodeResultService;
3032
import com.flow.platform.api.util.I18nUtil;
33+
import com.flow.platform.core.domain.Page;
34+
import com.flow.platform.core.domain.Pageable;
3135
import com.flow.platform.core.exception.NotFoundException;
3236
import com.flow.platform.util.Logger;
3337
import com.flow.platform.util.StringUtil;
@@ -69,6 +73,9 @@ public class JobController extends NodeController {
6973
@Autowired
7074
private LogService logService;
7175

76+
@Autowired
77+
private ArtifactService artifactService;
78+
7279
@Autowired
7380
private ThreadLocal<User> currentUser;
7481

@@ -143,6 +150,52 @@ public List<Job> index(@RequestParam Map<String, String> allParams, SearchCondit
143150
return searchService.search(condition, paths);
144151
}
145152

153+
/**
154+
* @api {get} /jobs/limit/:root List
155+
* @apiParam {String} [root] flow node path, return all jobs if not presented
156+
* @apiParam {String} [keyword] search keyword
157+
* @apiParam {String} [branch] search branch
158+
* @apiParam {String} [category] git event type
159+
* @apiParam {String} [creator] creator
160+
* @apiParam {int} [number] number
161+
* @apiParam {int} [size] size
162+
* @apiGroup Jobs
163+
* @apiDescription Get jobs by node path or list all jobs use page
164+
*
165+
* @apiSuccessExample {json} Success-Response
166+
* {
167+
* content:[
168+
* {
169+
* Job response json see Create response
170+
* },
171+
* {
172+
* ...
173+
* }
174+
* ],
175+
*
176+
* totalSize:11,
177+
* pageNumber:1,
178+
* pageSize:5,
179+
* pageCount:3
180+
* }
181+
*
182+
*/
183+
@GetMapping(path = "/limit/{root}")
184+
@WebSecurity(action = Actions.JOB_SHOW)
185+
public Page<Job> limitIndex(SearchCondition searchCondition, Pageable pageable) {
186+
String path = currentNodePath.get();
187+
188+
List<String> paths = null;
189+
if (path != null) {
190+
paths = Lists.newArrayList(path);
191+
}
192+
193+
if (Pageable.isEmpty(pageable)) {
194+
pageable = Pageable.DEFAULT;
195+
}
196+
return searchService.search(searchCondition, paths, pageable);
197+
}
198+
146199
/**
147200
* @api {get} /jobs/:root/:buildNumber Show
148201
* @apiParam {String} root flow node path
@@ -347,4 +400,9 @@ public Resource jobLog(@PathVariable Long buildNumber,
347400
return logService.findJobLog(path, buildNumber);
348401
}
349402

403+
@GetMapping(path = "/{root}/{buildNumber}/artifacts")
404+
public List<Artifact> artifacts(@PathVariable Long buildNumber) {
405+
return artifactService.list(currentNodePath.get(), buildNumber);
406+
}
407+
350408
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.flow.platform.api.controller;
18+
19+
import com.flow.platform.api.domain.LocalFileResource;
20+
import com.flow.platform.api.service.LocalFileResourceService;
21+
import javax.servlet.http.HttpServletResponse;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.core.io.Resource;
24+
import org.springframework.web.bind.annotation.GetMapping;
25+
import org.springframework.web.bind.annotation.PathVariable;
26+
import org.springframework.web.bind.annotation.PostMapping;
27+
import org.springframework.web.bind.annotation.RequestMapping;
28+
import org.springframework.web.bind.annotation.RequestPart;
29+
import org.springframework.web.bind.annotation.RestController;
30+
import org.springframework.web.multipart.MultipartFile;
31+
32+
/**
33+
* @author yh@firim
34+
*/
35+
@RestController
36+
@RequestMapping(path = "/local_file_resources")
37+
public class LocalFileResourceController {
38+
39+
@Autowired
40+
private LocalFileResourceService localFileResourceService;
41+
42+
@PostMapping
43+
public LocalFileResource post(@RequestPart(name = "file") MultipartFile file) {
44+
return localFileResourceService.create(file);
45+
}
46+
47+
@GetMapping(path = "/{id}")
48+
public Resource get(@PathVariable String id, HttpServletResponse httpResponse) {
49+
50+
LocalFileResource storage = localFileResourceService.get(id);
51+
httpResponse.setHeader(
52+
"Content-Disposition",
53+
String.format("attachment; filename=%s", storage.getName()));
54+
return localFileResourceService.getResource(id);
55+
}
56+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.flow.platform.api.dao;
18+
19+
import com.flow.platform.api.domain.Artifact;
20+
import com.flow.platform.core.dao.BaseDao;
21+
import java.math.BigInteger;
22+
import java.util.List;
23+
24+
/**
25+
* @author yh@firim
26+
*/
27+
public interface ArtifactDao extends BaseDao<Integer, Artifact> {
28+
29+
List<Artifact> list(BigInteger jobId);
30+
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.flow.platform.api.dao;
18+
19+
import com.flow.platform.api.domain.Artifact;
20+
import com.flow.platform.core.dao.AbstractBaseDao;
21+
import java.math.BigInteger;
22+
import java.util.List;
23+
import org.springframework.stereotype.Repository;
24+
25+
/**
26+
* @author yh@firim
27+
*/
28+
@Repository
29+
public class ArtifactDaoImpl extends AbstractBaseDao<Integer, Artifact> implements ArtifactDao {
30+
31+
@Override
32+
protected Class<Artifact> getEntityClass() {
33+
return Artifact.class;
34+
}
35+
36+
@Override
37+
protected String getKeyName() {
38+
return "id";
39+
}
40+
41+
@Override
42+
public List<Artifact> list(BigInteger jobId) {
43+
return execute(session -> session
44+
.createQuery("from Artifact where jobId = :id", getEntityClass())
45+
.setParameter("id", jobId)
46+
.list());
47+
}
48+
49+
}

platform-api/src/main/java/com/flow/platform/api/dao/CredentialDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ public interface CredentialDao extends BaseDao<String, Credential> {
3535
* List credential by types
3636
*/
3737
List<Credential> listByType(Collection<CredentialType> types);
38+
3839
}

platform-api/src/main/java/com/flow/platform/api/dao/CredentialDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ public List<Credential> listByType(Collection<CredentialType> types) {
5858
.setParameterList("types", types)
5959
.list());
6060
}
61+
6162
}
6263

platform-api/src/main/java/com/flow/platform/api/dao/FlowDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ public interface FlowDao extends BaseDao<String, Node> {
3232
* List flow path by created by email
3333
*/
3434
List<String> pathList(Collection<String> createdBy);
35+
3536
}

0 commit comments

Comments
 (0)