1 /*
2 * Copyright 2016-2024 Bloomreach B.V. (https://www.bloomreach.com)
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 package org.onehippo.forge.content.exim.core;
17
18 import java.util.Collection;
19
20 import org.apache.commons.vfs2.FileObject;
21 import org.onehippo.forge.content.pojo.model.ContentNode;
22 import org.slf4j.Logger;
23
24 /**
25 * Content Migration (Export or Import) Task interface.
26 */
27 public interface ContentMigrationTask {
28
29 /**
30 * Returns logger used by this task.
31 * @return logger used by this task
32 */
33 public Logger getLogger();
34
35 /**
36 * Sets a logger to be used by this task.
37 * @param logger logger to be used by this task
38 */
39 public void setLogger(Logger logger);
40
41 /**
42 * Starts this task. By 'starting', this task is supposed to reset its content migration records
43 * and initialize the internal data. e.g, started time milliseconds.
44 */
45 public void start();
46
47 /**
48 * Stops this task. By 'stopping', this task is supposed to update the internal data. e.g, stopped time milliseconds.
49 * But this task is supposed to keep the content migration records even after stopping for reporting purpose.
50 */
51 public void stop();
52
53 /**
54 * Returns the started time milliseconds.
55 * @return the started time milliseconds
56 */
57 public long getStartedTimeMillis();
58
59 /**
60 * Returns the stopped time milliseconds.
61 * @return the stopped time milliseconds
62 */
63 public long getStoppedTimeMillis();
64
65 /**
66 * Begins a new unit of content migration work item which can be identified by
67 * either {@code contentId} or {@code contentPath}.
68 * @param contentId content identifier for this unit of content migration work
69 * @param contentPath content path for this unit of content migration work
70 * @return a new {@link ContentMigrationRecord} instance
71 */
72 public ContentMigrationRecord beginRecord(String contentId, String contentPath);
73
74 /**
75 * Ends the current unit of content migration work item.
76 * @return the current {@link ContentMigrationRecord} instance
77 */
78 public ContentMigrationRecord endRecord();
79
80 /**
81 * Returns the collection containing all the content migration work item records.
82 * @return the collection containing all the content migration work item records
83 */
84 public Collection<ContentMigrationRecord> getContentMigrationRecords();
85
86 /**
87 * Return the execution summary.
88 * @return the execution summary
89 */
90 public String getSummary();
91
92 /**
93 * Logs the execution summary by using the logger.
94 */
95 public void logSummary();
96
97 /**
98 * Reads {@code sourceFile} containing a {@link ContentNode} data in JSON format
99 * and returns a parsed {@link ContentNode} object.
100 * @param sourceFile source file containing a {@link ContentNode} data in JSON format
101 * @return a parsed {@link ContentNode} object
102 * @throws ContentMigrationException if reading fails.
103 */
104 public ContentNode readContentNodeFromJsonFile(FileObject sourceFile) throws ContentMigrationException;
105
106 /**
107 * Writes {@code contentNode} object into {@code targetFile} in JSON format.
108 * @param contentNode a {@link ContentNode} object
109 * @param targetFile target file to write the {@code contentNode}
110 * @throws ContentMigrationException if writing fails.
111 */
112 public void writeContentNodeToJsonFile(ContentNode contentNode, FileObject targetFile)
113 throws ContentMigrationException;
114
115 /**
116 * Reads {@code sourceFile} containing a {@link ContentNode} data in XML format
117 * and returns a parsed {@link ContentNode} object.
118 * @param sourceFile source file containing a {@link ContentNode} data in XML format
119 * @return a parsed {@link ContentNode} object
120 * @throws ContentMigrationException if reading fails.
121 */
122 public ContentNode readContentNodeFromXmlFile(FileObject sourceFile) throws ContentMigrationException;
123
124 /**
125 * Writes {@code contentNode} object into {@code targetFile} in XML format.
126 * @param contentNode a {@link ContentNode} object
127 * @param targetFile target file to write the {@code contentNode}
128 * @throws ContentMigrationException if writing fails.
129 */
130 public void writeContentNodeToXmlFile(ContentNode contentNode, FileObject targetFile)
131 throws ContentMigrationException;
132
133 }