-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DHFPROD-1741 Add a generic Process class (#1765)
* Add a generic Process class * Adds copyright info
- Loading branch information
1 parent
927e6c6
commit 82b5513
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
marklogic-data-hub/src/main/java/com/marklogic/hub/processes/Process.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,90 @@ | ||
/* | ||
* Copyright 2012-2019 MarkLogic Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.marklogic.hub.processes; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
public interface Process { | ||
|
||
enum ProcessType { | ||
INGEST("ingest"), | ||
MAPPING("mapping"), | ||
CUSTOM("custom"); | ||
|
||
private String type; | ||
|
||
ProcessType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public static ProcessType getProcessType(String type) { | ||
for (ProcessType processType : ProcessType.values()) { | ||
if (processType.toString().equals(type)) { | ||
return processType; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public String toString() { | ||
return this.type; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the name of the processes | ||
* | ||
* @return a processes name | ||
*/ | ||
String getProcessName(); | ||
|
||
/** | ||
* Sets the name of the processes | ||
* | ||
* @param processName - a processes name | ||
*/ | ||
void setProcessName(String processName); | ||
|
||
/** | ||
* Returns the type of the Process | ||
* | ||
* @return - a processes type | ||
*/ | ||
ProcessType getProcessType(); | ||
|
||
/** | ||
* Sets the type of the processes | ||
* | ||
* @param processType - a processes type | ||
*/ | ||
void setProcessType(ProcessType processType); | ||
|
||
/** | ||
* Serializes the mapping as a json string | ||
* | ||
* @return the serialized JSON string | ||
*/ | ||
String serialize(); | ||
|
||
/** | ||
* Deserializes a json response and applies it to this mapping | ||
* | ||
* @param json - the JsonNode you want deserialize | ||
* @return this mapping | ||
*/ | ||
Process deserialize(JsonNode json); | ||
} |
68 changes: 68 additions & 0 deletions
68
marklogic-data-hub/src/main/java/com/marklogic/hub/processes/ProcessImpl.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 @@ | ||
/* | ||
* Copyright 2012-2019 MarkLogic Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.marklogic.hub.processes; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.marklogic.hub.error.DataHubProjectException; | ||
|
||
public class ProcessImpl implements Process { | ||
|
||
private String processName; | ||
private ProcessType processType; | ||
|
||
public String getProcessName() { | ||
return processName; | ||
} | ||
|
||
public void setProcessName(String processName) { | ||
this.processName = processName; | ||
} | ||
|
||
public ProcessType getProcessType() { | ||
return processType; | ||
} | ||
|
||
public void setProcessType(ProcessType processType) { | ||
this.processType = processType; | ||
} | ||
|
||
@Override | ||
public String serialize() { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
try { | ||
return mapper.writeValueAsString(this); | ||
} | ||
catch (JsonProcessingException e) { | ||
throw new DataHubProjectException("Unable to serialize processes object."); | ||
} | ||
} | ||
|
||
@Override | ||
public Process deserialize(JsonNode json) { | ||
if (json.has("name")) { | ||
setProcessName(json.get("name").asText()); | ||
} | ||
|
||
if (json.has("type")) { | ||
setProcessType(ProcessType.getProcessType(json.get("type").asText())); | ||
} | ||
|
||
return this; | ||
} | ||
} |