Skip to content

Commit 11571b7

Browse files
committed
Handled REST directory changes (found under <plugin directory>/entities/<entityName>/<flowtype>/REST and show if it is synched. Detection if modules are synched are done in the factories of entity, flow and rest models.
1 parent 5f19ed9 commit 11571b7

File tree

7 files changed

+126
-101
lines changed

7 files changed

+126
-101
lines changed

quick-start/src/main/java/com/marklogic/hub/factory/EntityModelFactory.java

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.marklogic.hub.flow.FlowType;
1616
import com.marklogic.hub.model.EntityModel;
1717
import com.marklogic.hub.model.FlowModel;
18+
import com.marklogic.hub.model.RestModel;
19+
import com.marklogic.hub.service.SyncStatusService;
1820
import com.marklogic.hub.util.FileUtil;
1921

2022
public class EntityModelFactory {
@@ -62,48 +64,54 @@ public EntityModel createNewEntity(File userPluginDir, String entityName,
6264
return entityModel;
6365
}
6466

65-
public EntityModel createEntity(String entityName, String entityFilePath) {
67+
public EntityModel createEntity(String entityName, String entityFilePath, SyncStatusService syncStatusService) {
6668
EntityModel entityModel = new EntityModel();
6769
entityModel.setEntityName(entityName);
70+
//this will be updated after traversing its modules
6871
entityModel.setSynched(this.entitiesInServer.containsKey(entityName));
69-
72+
7073
FlowModelFactory flowModelFactory = new FlowModelFactory(
7174
this.entitiesInServer.get(entityName), entityName);
72-
entityModel.setInputFlows(this.getInputFlows(flowModelFactory,
73-
entityFilePath));
74-
entityModel.setConformFlows(this.getConformFlows(flowModelFactory,
75-
entityFilePath));
75+
RestModelFactory restModelFactory = new RestModelFactory(entityName);
76+
setEntityModules(entityModel, entityFilePath, flowModelFactory, restModelFactory, syncStatusService);
7677

7778
return entityModel;
7879
}
7980

80-
private List<FlowModel> getInputFlows(FlowModelFactory flowModelFactory,
81-
String entityFilePath) {
82-
return this.getFlows(flowModelFactory, entityFilePath, FlowType.INPUT);
83-
}
84-
85-
private List<FlowModel> getConformFlows(FlowModelFactory flowModelFactory,
86-
String entityFilePath) {
87-
return this
88-
.getFlows(flowModelFactory, entityFilePath, FlowType.CONFORMANCE);
81+
//set the values of modules of the entity such as flows, rest, etc.
82+
private void setEntityModules(EntityModel entityModel, String entityFilePath,
83+
FlowModelFactory flowModelFactory, RestModelFactory restModelFactory, SyncStatusService syncStatusService) {
84+
this.setEntityModules(entityModel, entityFilePath, FlowType.INPUT, flowModelFactory, restModelFactory, syncStatusService);
85+
this.setEntityModules(entityModel, entityFilePath, FlowType.CONFORMANCE, flowModelFactory, restModelFactory, syncStatusService);
8986
}
9087

91-
private List<FlowModel> getFlows(FlowModelFactory flowModelFactory,
92-
String entityFilePath, FlowType flowType) {
93-
List<FlowModel> flows = new ArrayList<>();
94-
String flowsFilePath = entityFilePath + File.separator
88+
private void setEntityModules(EntityModel entityModel, String entityFilePath,
89+
FlowType flowType, FlowModelFactory flowModelFactory,
90+
RestModelFactory restModelFactory, SyncStatusService syncStatusService) {
91+
String modulesParentDirectory = entityFilePath + File.separator
9592
+ flowType.toString();
96-
List<String> flowNames = FileUtil.listDirectFolders(flowsFilePath);
97-
for (String flowName : flowNames) {
98-
// REST directory is not a flow. It's the rest options. skip it.
99-
if (flowName.equals("REST")) {
100-
continue;
93+
List<String> folderNames = FileUtil.listDirectFolders(modulesParentDirectory);
94+
95+
List<FlowModel> flows = new ArrayList<>();
96+
RestModel restModel = null;
97+
for (String folderName : folderNames) {
98+
if (folderName.equalsIgnoreCase(RestModelFactory.REST_FOLDER_NAME)) {
99+
restModel = restModelFactory.createRest(modulesParentDirectory, syncStatusService);
100+
entityModel.setSynched(entityModel.isSynched() && restModel.isSynched());
101+
} else {
102+
FlowModel flowModel = flowModelFactory.createFlow(modulesParentDirectory,
103+
folderName, flowType, syncStatusService);
104+
entityModel.setSynched(entityModel.isSynched() && flowModel.isSynched());
105+
flows.add(flowModel);
101106
}
102-
FlowModel flowModel = flowModelFactory.createFlow(flowsFilePath,
103-
flowName, flowType);
104-
flows.add(flowModel);
105107
}
106-
return flows;
108+
if(flowType == FlowType.INPUT) {
109+
entityModel.setInputFlows(flows);
110+
entityModel.setInputRest(restModel);
111+
} else {
112+
entityModel.setConformFlows(flows);
113+
entityModel.setConformRest(restModel);
114+
}
107115
}
108116

109117
public static Map<String, EntityModel> toEntityModelMap(

quick-start/src/main/java/com/marklogic/hub/factory/FlowModelFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.nio.file.Path;
56
import java.util.LinkedHashMap;
67
import java.util.List;
78
import java.util.Map;
@@ -13,6 +14,7 @@
1314
import com.marklogic.hub.flow.Flow;
1415
import com.marklogic.hub.flow.FlowType;
1516
import com.marklogic.hub.model.FlowModel;
17+
import com.marklogic.hub.service.SyncStatusService;
1618

1719
public class FlowModelFactory {
1820

@@ -57,7 +59,7 @@ public FlowModel createNewFlow(File userPluginDirPath, String flowName,
5759
}
5860

5961
public FlowModel createFlow(String parentDirPath, String flowName,
60-
FlowType flowType) {
62+
FlowType flowType, SyncStatusService syncStatusService) {
6163
FlowModel flowModel = new FlowModel();
6264
flowModel.setEntityName(entityName);
6365
flowModel.setFlowName(flowName);
@@ -67,10 +69,9 @@ public FlowModel createFlow(String parentDirPath, String flowName,
6769
flowModel.setTreeData(treeDataFactory.listFilesAndDirectories());
6870
Flow flow = this.flowsInServer.get(flowName);
6971
boolean synched = false;
70-
// TODO: confirm the value of the collector's type
71-
if (flow != null && flow.getCollector() != null
72-
&& flowType.equals(flow.getCollector().getType())) {
73-
synched = true;
72+
if (flow != null && flow.getType() != null
73+
&& flowType.equals(flow.getType())) {
74+
synched = syncStatusService.isDirectorySynched(absolutePath);
7475
}
7576
flowModel.setSynched(synched);
7677
return flowModel;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.marklogic.hub.factory;
2+
3+
import java.io.File;
4+
5+
import com.marklogic.hub.model.RestModel;
6+
import com.marklogic.hub.service.SyncStatusService;
7+
8+
public class RestModelFactory {
9+
10+
public static final String REST_FOLDER_NAME = "REST";
11+
private String entityName;
12+
13+
public RestModelFactory(String entityName) {
14+
this.entityName = entityName;
15+
}
16+
17+
public RestModel createRest(String parentDirPath, SyncStatusService syncStatusService) {
18+
RestModel restModel = new RestModel();
19+
restModel.setEntityName(entityName);
20+
String absolutePath = parentDirPath + File.separator + REST_FOLDER_NAME;
21+
restModel.setSynched(syncStatusService.isDirectorySynched(absolutePath));
22+
return restModel;
23+
}
24+
}

quick-start/src/main/java/com/marklogic/hub/model/EntityModel.java

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class EntityModel {
1010
private List<FlowModel> inputFlows;
1111
private List<FlowModel> conformFlows;
1212
private boolean isSynched;
13+
private RestModel inputRest;
14+
private RestModel conformRest;
1315

1416
public String getEntityName() {
1517
return entityName;
@@ -82,37 +84,22 @@ public void setConformFlowsSynched(boolean synched) {
8284
}
8385
}
8486
}
85-
86-
public void copySyncStatusFrom(EntityModel oldModel) {
87-
if (oldModel == null) {
88-
return;
89-
}
90-
if (!entityName.equals(oldModel.getEntityName())) {
91-
return;
92-
}
93-
94-
setSynched(oldModel.isSynched());
95-
96-
Map<String, FlowModel> inputFlowModels = oldModel.getInputFlowsAsMap();
97-
if (inputFlows != null) {
98-
for (FlowModel model : inputFlows) {
99-
FlowModel oldFlow = inputFlowModels.get(model.getFlowName());
100-
if (oldFlow != null) {
101-
model.setSynched(oldFlow.isSynched());
102-
}
103-
}
104-
}
105-
106-
Map<String, FlowModel> conformFlowModels = oldModel.getConformFlowsAsMap();
107-
if (conformFlows != null) {
108-
for (FlowModel model : conformFlows) {
109-
FlowModel oldFlow = conformFlowModels.get(model.getFlowName());
110-
if (oldFlow != null) {
111-
model.setSynched(oldFlow.isSynched());
112-
}
113-
}
114-
}
115-
}
87+
88+
public RestModel getInputRest() {
89+
return inputRest;
90+
}
91+
92+
public void setInputRest(RestModel inputRest) {
93+
this.inputRest = inputRest;
94+
}
95+
96+
public RestModel getConformRest() {
97+
return conformRest;
98+
}
99+
100+
public void setConformRest(RestModel conformRest) {
101+
this.conformRest = conformRest;
102+
}
116103

117104
@Override
118105
public String toString() {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.marklogic.hub.model;
2+
3+
public class RestModel {
4+
5+
private String entityName;
6+
private boolean isSynched;
7+
8+
public String getEntityName() {
9+
return entityName;
10+
}
11+
12+
public void setEntityName(String entityName) {
13+
this.entityName = entityName;
14+
}
15+
16+
public boolean isSynched() {
17+
return isSynched;
18+
}
19+
20+
public void setSynched(boolean isSynched) {
21+
this.isSynched = isSynched;
22+
}
23+
24+
@Override
25+
public String toString() {
26+
StringBuilder sb = new StringBuilder();
27+
sb.append("{");
28+
sb.append("entityName=");
29+
sb.append(entityName);
30+
sb.append("isSynched=");
31+
sb.append(isSynched);
32+
sb.append("}");
33+
34+
return sb.toString();
35+
}
36+
}

quick-start/src/main/java/com/marklogic/hub/service/EntityManagerService.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,12 @@ public List<EntityModel> getEntities() {
6464
for (String entityName : entityNames) {
6565
LOGGER.debug("Entity : " + entityName);
6666
entities.add(entityModelFactory.createEntity(entityName,
67-
entitiesPath + File.separator + entityName));
67+
entitiesPath + File.separator + entityName, syncStatusService));
6868
}
69-
70-
// update the sync status of the entities and flows
71-
// TODO: if we improve EntityModelFactory and FlowModelFactory
72-
// implementation,
73-
// we may be able to set the status correctly during model creation.
74-
updateSyncStatus(entities);
75-
69+
7670
return entities;
7771
}
78-
79-
protected void updateSyncStatus(List<EntityModel> entities) {
80-
for (EntityModel entityModel : entities) {
81-
boolean flowsSynched = true;
82-
for (FlowModel flowModel : entityModel.getInputFlows()) {
83-
boolean flowSynched = syncStatusService.isFlowSynched(entityModel.getEntityName(), FlowType.INPUT, flowModel.getFlowName());
84-
flowsSynched = flowsSynched && flowSynched;
85-
flowModel.setSynched(flowSynched);
86-
}
87-
88-
for (FlowModel flowModel : entityModel.getConformFlows()) {
89-
boolean flowSynched = syncStatusService.isFlowSynched(entityModel.getEntityName(), FlowType.CONFORM, flowModel.getFlowName());
90-
flowsSynched = flowsSynched && flowSynched;
91-
flowModel.setSynched(flowSynched);
92-
}
93-
94-
entityModel.setSynched(flowsSynched);
95-
}
96-
97-
}
98-
72+
9973
private List<Entity> getEntitysInServer() {
10074
List<Entity> entitiesInServer = new ArrayList<>();
10175
try {

quick-start/src/main/java/com/marklogic/hub/service/SyncStatusService.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.nio.file.FileVisitor;
77
import java.nio.file.Files;
88
import java.nio.file.Path;
9-
import java.nio.file.Paths;
109
import java.nio.file.attribute.BasicFileAttributes;
1110

1211
import org.springframework.beans.factory.InitializingBean;
@@ -17,7 +16,6 @@
1716

1817
import com.marklogic.client.modulesloader.impl.PropertiesModuleManager;
1918
import com.marklogic.hub.config.EnvironmentConfiguration;
20-
import com.marklogic.hub.model.FlowType;
2119

2220
@Service
2321
@Scope(scopeName=WebApplicationContext.SCOPE_SESSION)
@@ -47,15 +45,12 @@ private boolean isSynched(File file) throws IOException {
4745
}
4846

4947

50-
public boolean isFlowSynched(String entityName, FlowType flowType, String flowName) {
48+
public boolean isDirectorySynched(String absolutePath) {
5149
moduleManager.initialize();
52-
String pluginDir = environmentConfiguration.getUserPluginDir();
53-
Path flowDir = Paths.get(pluginDir, "entities", entityName, flowType.toString(), flowName);
54-
5550
boolean synched = false;
5651
try {
5752
PluginDirectoryVisitor visitor = new PluginDirectoryVisitor();
58-
Files.walkFileTree(new File(flowDir.toString()).toPath(), visitor);
53+
Files.walkFileTree(new File(absolutePath).toPath(), visitor);
5954

6055
synched = visitor.isSynched();
6156
} catch (IOException e) {
@@ -80,7 +75,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
8075
@Override
8176
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
8277
// don't look at hidden files like .DS_Store
83-
if (!file.getFileName().toString().startsWith(".")) {
78+
if (!file.getFileName().toString().startsWith(".") && !file.toAbsolutePath().toString().contains("metadata")) {
8479
synched = synched && SyncStatusService.this.isSynched(file.normalize().toAbsolutePath().toFile());
8580
if (!synched) {
8681
return FileVisitResult.TERMINATE;

0 commit comments

Comments
 (0)