Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Start Flows tree directory and form validations #36

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.marklogic.hub.exception;

public class FormValidationException extends RuntimeException {

private static final long serialVersionUID = 7251931269628838437L;

public FormValidationException(String message, Throwable cause) {
super(message, cause);
}

public FormValidationException(String message) {
super(message);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,84 +14,84 @@

public class DomainModelFactory {

private Map<String, Domain> domainsInServer = new LinkedHashMap<>();

public DomainModelFactory() {
// use this when creating a new domain in the client
}

public DomainModelFactory(List<Domain> domains) {
// use this when comparing domains in the client and server
if (domains != null) {
for (Domain domain : domains) {
domainsInServer.put(domain.getName(), domain);
}
}
}

public DomainModel createNewDomain(String userPluginDir, String domainName,
String inputFlowName, String conformFlowName) {
DomainModel domainModel = new DomainModel();
domainModel.setDomainName(domainName);
domainModel.setInputFlows(new ArrayList<>());
domainModel.setConformFlows(new ArrayList<>());
FileUtil.createFolderIfNecessary(userPluginDir + File.separator
+ FileUtil.DOMAINS_FOLDER, domainName);

FlowModelFactory flowModelFactory = new FlowModelFactory(domainName);
String domainDirPath = userPluginDir + File.separator
+ FileUtil.DOMAINS_FOLDER + File.separator + domainName;
FlowModel inputFlow = flowModelFactory.createNewFlow(domainDirPath
+ File.separator + FlowType.INPUT, inputFlowName,
FlowType.INPUT);
FlowModel conformFlow = flowModelFactory.createNewFlow(domainDirPath
+ File.separator + FlowType.CONFORM, conformFlowName,
FlowType.CONFORM);

domainModel.getInputFlows().add(inputFlow);
domainModel.getConformFlows().add(conformFlow);

return domainModel;
}

public DomainModel createDomain(String domainName, String domainFilePath) {
DomainModel domainModel = new DomainModel();
domainModel.setDomainName(domainName);
domainModel.setSynched(this.domainsInServer.containsKey(domainName));

FlowModelFactory flowModelFactory = new FlowModelFactory(
this.domainsInServer.get(domainName), domainName);
domainModel.setInputFlows(this.getInputFlows(flowModelFactory,
domainFilePath));
domainModel.setConformFlows(this.getConformFlows(flowModelFactory,
domainFilePath));

return domainModel;
}

private List<FlowModel> getInputFlows(FlowModelFactory flowModelFactory,
String domainFilePath) {
return this.getFlows(flowModelFactory, domainFilePath, FlowType.INPUT);
}

private List<FlowModel> getConformFlows(FlowModelFactory flowModelFactory,
String domainFilePath) {
return this
.getFlows(flowModelFactory, domainFilePath, FlowType.CONFORM);
}

private List<FlowModel> getFlows(FlowModelFactory flowModelFactory,
String domainFilePath, FlowType flowType) {
List<FlowModel> flows = new ArrayList<>();
String flowsFilePath = domainFilePath + File.separator
+ flowType.getName();
List<String> flowNames = FileUtil.listDirectFolders(flowsFilePath);
for (String flowName : flowNames) {
FlowModel flowModel = flowModelFactory.createFlow(flowsFilePath,
flowName, flowType);
flows.add(flowModel);
}
return flows;
}
private Map<String, Domain> domainsInServer = new LinkedHashMap<>();

public DomainModelFactory() {
// use this when creating a new domain in the client
}

public DomainModelFactory(List<Domain> domains) {
// use this when comparing domains in the client and server
if (domains != null) {
for (Domain domain : domains) {
domainsInServer.put(domain.getName(), domain);
}
}
}

public DomainModel createNewDomain(String userPluginDir, String domainName,
String inputFlowName, String conformFlowName) {
DomainModel domainModel = new DomainModel();
domainModel.setDomainName(domainName);
domainModel.setInputFlows(new ArrayList<>());
domainModel.setConformFlows(new ArrayList<>());
FileUtil.createFolderIfNecessary(userPluginDir + File.separator
+ FileUtil.DOMAINS_FOLDER, domainName);

FlowModelFactory flowModelFactory = new FlowModelFactory(domainName);
String domainDirPath = userPluginDir + File.separator
+ FileUtil.DOMAINS_FOLDER + File.separator + domainName;
FlowModel inputFlow = flowModelFactory.createNewFlow(domainDirPath
+ File.separator + FlowType.INPUT.getName(), inputFlowName,
FlowType.INPUT);
FlowModel conformFlow = flowModelFactory.createNewFlow(domainDirPath
+ File.separator + FlowType.CONFORM.getName(), conformFlowName,
FlowType.CONFORM);

domainModel.getInputFlows().add(inputFlow);
domainModel.getConformFlows().add(conformFlow);

return domainModel;
}

public DomainModel createDomain(String domainName, String domainFilePath) {
DomainModel domainModel = new DomainModel();
domainModel.setDomainName(domainName);
domainModel.setSynched(this.domainsInServer.containsKey(domainName));

FlowModelFactory flowModelFactory = new FlowModelFactory(
this.domainsInServer.get(domainName), domainName);
domainModel.setInputFlows(this.getInputFlows(flowModelFactory,
domainFilePath));
domainModel.setConformFlows(this.getConformFlows(flowModelFactory,
domainFilePath));

return domainModel;
}

private List<FlowModel> getInputFlows(FlowModelFactory flowModelFactory,
String domainFilePath) {
return this.getFlows(flowModelFactory, domainFilePath, FlowType.INPUT);
}

private List<FlowModel> getConformFlows(FlowModelFactory flowModelFactory,
String domainFilePath) {
return this
.getFlows(flowModelFactory, domainFilePath, FlowType.CONFORM);
}

private List<FlowModel> getFlows(FlowModelFactory flowModelFactory,
String domainFilePath, FlowType flowType) {
List<FlowModel> flows = new ArrayList<>();
String flowsFilePath = domainFilePath + File.separator
+ flowType.getName();
List<String> flowNames = FileUtil.listDirectFolders(flowsFilePath);
for (String flowName : flowNames) {
FlowModel flowModel = flowModelFactory.createFlow(flowsFilePath,
flowName, flowType);
flows.add(flowModel);
}
return flows;
}

}
Loading