Skip to content

Commit

Permalink
automatically reformatted using google-java-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihengSun committed Mar 24, 2024
1 parent bed8f27 commit 24c5069
Show file tree
Hide file tree
Showing 120 changed files with 20,163 additions and 20,937 deletions.
247 changes: 114 additions & 133 deletions src/main/java/com/gw/GeoweaverApplication.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.gw;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import com.google.api.client.util.Value;
import com.gw.jpa.GWUser;
import com.gw.jpa.Host;
Expand All @@ -13,15 +8,18 @@
import com.gw.utils.BaseTool;
import com.gw.utils.BeanTool;
import com.gw.utils.RandomString;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.log4j.Logger;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.boot.Banner;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
Expand All @@ -34,190 +32,173 @@
@EnableSwagger2
public class GeoweaverApplication {

static Logger logger = Logger.getLogger(GeoweaverApplication.class);

@Value("${geoweaver.workspace}")
private static String workspace;
static Logger logger = Logger.getLogger(GeoweaverApplication.class);

public static void main(String[] args) {
@Value("${geoweaver.workspace}")
private static String workspace;

// if we have a command line argument, we assume it is a command
if(args.length > 0) {
public static void main(String[] args) {

// Do not open homepage if we are running a command
// Run the spring boot application and command it to exit, so that only the command is run
// Create a spring boot application without tomcat
System.exit(SpringApplication.exit(new SpringApplicationBuilder(GeoweaverCLI.class)
.lazyInitialization(true)
.web(WebApplicationType.NONE)
.bannerMode(Banner.Mode.OFF)
.run(args)));
// if we have a command line argument, we assume it is a command
if (args.length > 0) {

// Do not open homepage if we are running a command
// Run the spring boot application and command it to exit, so that only the command is run
// Create a spring boot application without tomcat
System.exit(
SpringApplication.exit(
new SpringApplicationBuilder(GeoweaverCLI.class)
.lazyInitialization(true)
.web(WebApplicationType.NONE)
.bannerMode(Banner.Mode.OFF)
.run(args)));

}else{
} else {

ApplicationContext applicationContext = new SpringApplicationBuilder(GeoweaverApplication.class)
.bannerMode(Banner.Mode.OFF)
.run(args);
ApplicationContext applicationContext =
new SpringApplicationBuilder(GeoweaverApplication.class)
.bannerMode(Banner.Mode.OFF)
.run(args);

addDefaultPublicUser();
addDefaultPublicUser();

addLocalhost();
addLocalhost();

System.out.println("GeoWeaver is started and ready for use..");
System.out.println("URL: http://localhost:8070/Geoweaver");

}



}

@Bean
public Docket geoweaverAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
System.out.println("GeoWeaver is started and ready for use..");
System.out.println("URL: http://localhost:8070/Geoweaver");
}
}

public static void addLocalhost(){

HostTool ht = BeanTool.getBean(HostTool.class);
@Bean
public Docket geoweaverAPI() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}

Host h = ht.getHostById("100001");
public static void addLocalhost() {

if(h==null){
HostTool ht = BeanTool.getBean(HostTool.class);

logger.info("Localhost doesn't exist. Adding now..");
Host h = ht.getHostById("100001");

h = new Host();
if (h == null) {

h.setId("100001");
logger.info("Localhost doesn't exist. Adding now..");

h.setIp("127.0.0.1");
h = new Host();

h.setConfidential("FALSE");
h.setId("100001");

h.setName("Localhost");
h.setIp("127.0.0.1");

h.setOwner("111111");
h.setConfidential("FALSE");

h.setPort("22");
h.setName("Localhost");

h.setType("ssh");
h.setOwner("111111");

h.setUrl("http://localhost/");
h.setPort("22");

h.setUsername("publicuser");
h.setType("ssh");

ht.save(h);
h.setUrl("http://localhost/");

}else{
h.setUsername("publicuser");

logger.info("Localhost exists.");
ht.save(h);

}
} else {

// read password file
try{

BaseTool bt = BeanTool.getBean(BaseTool.class);

if(BaseTool.isNull(bt.getLocalhostPassword())){
logger.info("Localhost exists.");
}

String initialpassword = new RandomString(30).nextString();
// read password file
try {

logger.warn("\n============\n");
BaseTool bt = BeanTool.getBean(BaseTool.class);

logger.warn("Default password for Localhost: \n\n " + initialpassword+ "\n\n");
if (BaseTool.isNull(bt.getLocalhostPassword())) {

logger.warn("Please copy and save the password in a safe place");
String initialpassword = new RandomString(30).nextString();

logger.warn("Change password: <java -jar geoweaver.jar resetpassword>");
logger.warn("\n============\n");

logger.warn("\n============\n");

bt.setLocalhostPassword(initialpassword, false);
logger.warn("Default password for Localhost: \n\n " + initialpassword + "\n\n");

}
logger.warn("Please copy and save the password in a safe place");



}catch(Exception e){
logger.warn("Change password: <java -jar geoweaver.jar resetpassword>");

e.printStackTrace();
logger.warn("\n============\n");

}
bt.setLocalhostPassword(initialpassword, false);
}

} catch (Exception e) {

e.printStackTrace();
}
}

public static void addDefaultPublicUser(){
public static void addDefaultPublicUser() {

// fixed public user "public_user", id: "111111"
// all the created resources will be assigned to this user

UserTool ut = BeanTool.getBean(UserTool.class);
// fixed public user "public_user", id: "111111"
// all the created resources will be assigned to this user

GWUser publicuser = ut.getUserById("111111");
UserTool ut = BeanTool.getBean(UserTool.class);

if(publicuser==null){
GWUser publicuser = ut.getUserById("111111");

logger.warn("Public User doesn't exist. Adding now..");
if (publicuser == null) {

publicuser = new GWUser();
logger.warn("Public User doesn't exist. Adding now..");

publicuser.setEmail("[email protected]");
publicuser = new GWUser();

publicuser.setId("111111");
publicuser.setEmail("[email protected]");

publicuser.setIsactive(true);
publicuser.setId("111111");

publicuser.setPassword("wsorpwiuerkls;kldjfuiwperuewsldjf;lks"); //none can decrypt this code
publicuser.setIsactive(true);

publicuser.setUsername("publicuser");
publicuser.setPassword("wsorpwiuerkls;kldjfuiwperuewsldjf;lks"); // none can decrypt this code

ut.save(publicuser);
publicuser.setUsername("publicuser");

}else{
ut.save(publicuser);

logger.info("Public user exists.");

}

//set everything that doesn't have an owner to this user
ut.belongToPublicUser();
} else {

logger.info("Public user exists.");
}

public static void openHomePage(){

browse("http://localhost:8070/Geoweaver/");

}

public static void browse(String url) {
if(Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(url));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}else{
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
// set everything that doesn't have an owner to this user
ut.belongToPublicUser();
}

public static void openHomePage() {

browse("http://localhost:8070/Geoweaver/");
}

public static void browse(String url) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(url));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
} else {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}


}
}


Loading

0 comments on commit 24c5069

Please sign in to comment.