Skip to content

Commit e078a66

Browse files
committed
#558 redeploy modules after changing entity name
1 parent 6eaa3b2 commit e078a66

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.marklogic.hub.flow.FlowType;
3636
import com.marklogic.hub.scaffold.Scaffolding;
3737
import com.marklogic.quickstart.auth.ConnectionAuthenticationToken;
38+
import com.marklogic.quickstart.listeners.DeployUserModulesListener;
39+
import com.marklogic.quickstart.listeners.ValidateListener;
3840
import com.marklogic.quickstart.model.EnvironmentConfig;
3941
import com.marklogic.quickstart.model.FlowModel;
4042
import com.marklogic.quickstart.model.PluginModel;
@@ -63,7 +65,7 @@
6365
import java.util.regex.Pattern;
6466

6567
@Service
66-
public class EntityManagerService {
68+
public class EntityManagerService implements DeployUserModulesListener, ValidateListener {
6769

6870
private static final String UI_LAYOUT_FILE = "entities.layout.json";
6971
private static final String PLUGINS_DIR = "plugins";
@@ -76,6 +78,9 @@ public class EntityManagerService {
7678
@Autowired
7779
private FileSystemWatcherService watcherService;
7880

81+
@Autowired
82+
private DataHubService dataHubService;
83+
7984
private EnvironmentConfig envConfig() {
8085
ConnectionAuthenticationToken authenticationToken = (ConnectionAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
8186
return authenticationToken.getEnvironmentConfig();
@@ -176,15 +181,24 @@ public EntityModel saveEntity(EntityModel entity) throws IOException {
176181
// Update the name of the entity definition file
177182
File origFile = new File(fullpath);
178183
File newFile = new File(origFile.getParent() + File.separator + title + ENTITY_FILE_EXTENSION);
179-
origFile.renameTo(newFile);
184+
if (!origFile.renameTo(newFile)) {
185+
throw new IOException("Unable to rename " + origFile.getAbsolutePath() + " to " +
186+
newFile.getAbsolutePath());
187+
};
180188

181189
// Update the directory name
182190
File origDirectory = new File(origFile.getParent());
183191
File newDirectory = new File(origDirectory.getParent() + File.separator + title);
184-
origDirectory.renameTo(newDirectory);
192+
if (!origDirectory.renameTo(newDirectory)) {
193+
throw new IOException("Unable to rename " + origDirectory.getAbsolutePath() + " to " +
194+
newDirectory.getAbsolutePath());
195+
}
185196

186197
fullpath = newDirectory.getAbsolutePath() + File.separator + title + ENTITY_FILE_EXTENSION;
187198
entity.setFilename(fullpath);
199+
200+
// Redeploy the flows
201+
dataHubService.reinstallUserModules(envConfig().getMlSettings(), this, this);
188202
}
189203
}
190204

@@ -372,4 +386,14 @@ private Map<String, HubUIData> getUiData() throws IOException {
372386

373387
return uiDataList;
374388
}
389+
390+
@Override
391+
public void onDeploy(String status) {
392+
// No action needed
393+
}
394+
395+
@Override
396+
public void onValidate(JsonNode validation) {
397+
// No action needed
398+
}
375399
}

0 commit comments

Comments
 (0)