Skip to content

Commit bca0d0e

Browse files
committed
File API fixes
1 parent 8292ed6 commit bca0d0e

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

karavan-app/src/main/java/org/apache/camel/karavan/api/ProjectFileResource.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public class ProjectFileResource {
3838
@Inject
3939
KaravanCache karavanCache;
4040

41-
@Inject
42-
CodeService codeService;
43-
4441
@GET
4542
@Produces(MediaType.APPLICATION_JSON)
4643
@Path("/{projectId}")
@@ -129,16 +126,19 @@ public void delete(@PathParam("project") String project,
129126

130127
@POST
131128
@Produces(MediaType.APPLICATION_JSON)
132-
@Path("/copy/{project}")
133-
public Response copy(@PathParam("project") String project, JsonObject copy) throws Exception {
134-
var projectId = URLDecoder.decode(project, StandardCharsets.UTF_8);
135-
var from = copy.getString("from");
136-
var to = copy.getString("to");
137-
var tofile = karavanCache.getProjectFile(projectId, to);
138-
if (tofile == null) {
139-
var file = karavanCache.getProjectFile(projectId, from);
129+
@Path("/copy")
130+
public Response copy(JsonObject copy) throws Exception {
131+
var fromProjectId = copy.getString("fromProjectId");
132+
var fromFilename = copy.getString("fromFilename");
133+
var toProjectId = copy.getString("toProjectId");
134+
var toFilename = copy.getString("toFilename");
135+
var overwrite = copy.getBoolean("overwrite", false);
136+
var tofile = karavanCache.getProjectFile(toProjectId, toFilename);
137+
if (overwrite || tofile == null) {
138+
var file = karavanCache.getProjectFile(fromProjectId, fromFilename);
140139
var copyFile = file.copy();
141-
copyFile.setName(to);
140+
copyFile.setProjectId(toProjectId);
141+
copyFile.setName(toFilename);
142142
karavanCache.saveProjectFile(copyFile, false, false);
143143
return Response.ok().build();
144144
} else {

karavan-app/src/main/webui/src/api/KaravanApi.tsx

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,6 @@ export class KaravanApi {
208208
});
209209
}
210210

211-
static async getProjectDeploymentStatus(projectId: string, env: string, after: (status?: DeploymentStatus) => void) {
212-
instance.get('/ui/status/deployment/' + projectId + "/" + env)
213-
.then(res => {
214-
if (res.status === 200) {
215-
after(res.data);
216-
} else if (res.status === 204) {
217-
after(undefined);
218-
}
219-
}).catch(err => {
220-
ErrorEventBus.sendApiError(err);
221-
});
222-
}
223-
224-
static async getProjectCamelStatus(projectId: string, env: string, after: (status: CamelStatus) => void) {
225-
instance.get('/ui/status/camel/' + projectId + "/" + env)
226-
.then(res => {
227-
if (res.status === 200) {
228-
after(res.data);
229-
}
230-
}).catch(err => {
231-
ErrorEventBus.sendApiError(err);
232-
});
233-
}
234-
235211
static async getAllCamelContextStatuses(after: (statuses: CamelStatus[]) => void) {
236212
instance.get('/ui/status/camel/context')
237213
.then(res => {
@@ -390,6 +366,15 @@ export class KaravanApi {
390366
});
391367
}
392368

369+
static async copyProjectFile(fromProjectId: string, fromFilename: string, toProjectId: string, toFilename: string, overwrite: boolean, after: (res: AxiosResponse<any>) => void) {
370+
instance.post('/ui/file/copy', {fromProjectId: fromProjectId, fromFilename: fromFilename, toProjectId: toProjectId, toFilename: toFilename, overwrite: overwrite})
371+
.then(res => {
372+
after(res);
373+
}).catch(err => {
374+
after(err);
375+
});
376+
}
377+
393378
static async push(params: {}, after: (res: AxiosResponse<any>) => void) {
394379
instance.post('/ui/git', params)
395380
.then(res => {

0 commit comments

Comments
 (0)