-
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.
Merge pull request #26 from maeisabelle/Quick-Start-UIChanges
Quick Start UI and configuration changes
- Loading branch information
Showing
14 changed files
with
278 additions
and
58 deletions.
There are no files selected for viewing
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
138 changes: 108 additions & 30 deletions
138
quick-start/src/main/java/com/marklogic/hub/config/EnvironmentConfiguration.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 |
---|---|---|
@@ -1,84 +1,162 @@ | ||
package com.marklogic.hub.config; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Properties; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
/*** | ||
* | ||
* @author mturiana | ||
* This class is used to get the value of the keys in application.properties | ||
* @author mturiana This class is used to get the value of the keys in | ||
* application.properties | ||
*/ | ||
@Component | ||
public class EnvironmentConfiguration { | ||
|
||
private static final Logger LOGGER = LoggerFactory | ||
.getLogger(EnvironmentConfiguration.class); | ||
|
||
private static final String PROPERTIES_FILENAME = "environment.properties"; | ||
|
||
@Autowired | ||
private Environment environment; | ||
|
||
private Properties properties = new Properties(); | ||
|
||
public String getServerPort() { | ||
return this.environment.getProperty("server.port"); | ||
} | ||
|
||
|
||
|
||
public String getMLHost() { | ||
String value = this.properties.getProperty("mlHost"); | ||
if(value == null) { | ||
value = this.environment.getProperty("mlHost.default"); | ||
if (value != null) { | ||
return value; | ||
} | ||
return value; | ||
value = this.environment.getProperty("mlHost"); | ||
if (value != null) { | ||
this.properties.setProperty("mlHost", value); | ||
return value; | ||
} | ||
return this.environment.getProperty("mlHost.default"); | ||
} | ||
|
||
public String getMLUsername() { | ||
String value = this.properties.getProperty("mlUsername"); | ||
if(value == null) { | ||
value = this.environment.getProperty("mlUsername.default"); | ||
if (value != null) { | ||
return value; | ||
} | ||
return value; | ||
value = this.environment.getProperty("mlUsername"); | ||
if (value != null) { | ||
this.properties.setProperty("mlUsername", value); | ||
return value; | ||
} | ||
return this.environment.getProperty("mlUsername.default"); | ||
} | ||
|
||
public String getMLPassword() { | ||
String value = this.properties.getProperty("mlPassword"); | ||
if(value == null) { | ||
value = this.environment.getProperty("mlPassword.default"); | ||
if (value != null) { | ||
return value; | ||
} | ||
value = this.environment.getProperty("mlPassword"); | ||
if (value != null) { | ||
this.properties.setProperty("mlPassword", value); | ||
return value; | ||
} | ||
return value; | ||
return this.environment.getProperty("mlPassword.default"); | ||
} | ||
|
||
public String getMLRestPort() { | ||
String value = this.properties.getProperty("mlRestPort"); | ||
if(value == null) { | ||
value = this.environment.getProperty("mlRestPort.default"); | ||
if (value != null) { | ||
return value; | ||
} | ||
return value; | ||
value = this.environment.getProperty("mlRestPort"); | ||
if (value != null) { | ||
this.properties.setProperty("mlRestPort", value); | ||
return value; | ||
} | ||
return this.environment.getProperty("mlRestPort.default"); | ||
} | ||
|
||
public String getMLAuth() { | ||
String value = this.properties.getProperty("mlAuth"); | ||
if(value == null) { | ||
value = this.environment.getProperty("mlAuth.default"); | ||
if (value != null) { | ||
return value; | ||
} | ||
return value; | ||
value = this.environment.getProperty("mlAuth"); | ||
if (value != null) { | ||
this.properties.setProperty("mlAuth", value); | ||
return value; | ||
} | ||
return this.environment.getProperty("mlAuth.default"); | ||
} | ||
|
||
public void setMLHost(String mlHost) { | ||
this.properties.setProperty("mlHost", mlHost); | ||
} | ||
|
||
public void setMLRestPort(String mlRestPort) { | ||
this.properties.setProperty("mlRestPort", mlRestPort); | ||
this.properties.setProperty("mlRestPort", mlRestPort); | ||
} | ||
|
||
public void setMLUsername(String mlUsername) { | ||
this.properties.setProperty("mlUsername", mlUsername); | ||
} | ||
|
||
public void setMLPassword(String mlPassword) { | ||
this.properties.setProperty("mlPassword", mlPassword); | ||
} | ||
|
||
public void loadConfigurationFromFile() { | ||
InputStream is = null; | ||
try { | ||
File file = new File(PROPERTIES_FILENAME); | ||
if(file.exists()) { | ||
is = new FileInputStream( file ); | ||
properties.load( is ); | ||
} | ||
} catch ( Exception e ) { | ||
is = null; | ||
} | ||
} | ||
|
||
public void saveConfigurationToFile() { | ||
OutputStream out = null; | ||
try { | ||
out = new FileOutputStream(new File(PROPERTIES_FILENAME)); | ||
this.properties.store(out, null); | ||
} catch (FileNotFoundException e) { | ||
LOGGER.error("environment.properties is not found", e.getMessage()); | ||
} catch (IOException e) { | ||
LOGGER.error("Error saving configuration.", e.getMessage()); | ||
} finally { | ||
if (out != null) { | ||
try { | ||
out.close(); | ||
} catch (IOException e) { | ||
LOGGER.error("Error closing output stream.", e.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void removeSavedConfiguration() { | ||
this.properties = new Properties(); | ||
File file = new File(PROPERTIES_FILENAME); | ||
if(file.exists()) { | ||
file.delete(); | ||
} | ||
} | ||
|
||
} |
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
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
27 changes: 27 additions & 0 deletions
27
quick-start/src/main/java/com/marklogic/hub/web/form/BaseForm.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,27 @@ | ||
package com.marklogic.hub.web.form; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BaseForm { | ||
|
||
private boolean hasErrors; | ||
private List<String> errors = new ArrayList<String>(); | ||
|
||
public boolean isHasErrors() { | ||
return hasErrors; | ||
} | ||
public void setHasErrors(boolean hasErrors) { | ||
this.hasErrors = hasErrors; | ||
} | ||
public List<String> getErrors() { | ||
return errors; | ||
} | ||
public void setErrors(List<String> errors) { | ||
this.errors = errors; | ||
} | ||
|
||
|
||
|
||
|
||
} |
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
Oops, something went wrong.