Skip to content

Commit 746d123

Browse files
committed
Lesen der propeties geht.
1 parent 0693a4d commit 746d123

6 files changed

Lines changed: 35 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
## Getting Started
44
To use this program, you need a client secret. For more information, visit [Google Docs](https://developers.google.com/adwords/api/docs/guides/authentication).
5-
The client secret is stored in the [config.properties](https://github.com/localhostPIB/YoutubeApi/blob/master/src/main/resources/config.properties) file.
6-
The Main method class Starter.java starts the application as argument the video id is needed.
7-
e.g. https://www.youtube.com/watch?v={video-id}
8-
5+
The Main method class Starter.java starts the application, as arguments the client secret and video-id (e.g. https://www.youtube.com/watch?v={video-id}) are needed.
6+
Command: `java -jar YoutubeApi-1.0-SNAPSHOT-jar-with-dependencies.jar videoId Client-Secret`
97
## Built With
108
For this we use the build management tool Maven(v. 3.8.4) from the Apache Software Foundation.
119
* [Maven](https://maven.apache.org/)

src/main/java/Starter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import service.api.videoInformations.GetYTVideoInformations;
33
import dao.*;
44
import service.csv.CreateCSVFile;
5+
import util.FileUtils;
6+
import util.PropertyUtils;
57
import util.validator.StringValidator;
68

79
public class Starter {
@@ -12,7 +14,13 @@ public class Starter {
1214
* @throws Exception
1315
*/
1416
public static void main(String[] args) throws Exception {
15-
if (args.length == 1 && StringValidator.validateArgument(args[0])) {
17+
if (args.length >= 1 && StringValidator.validateArgument(args[0])) {
18+
19+
if (args.length == 2 && StringValidator.validateArgument(args[1])
20+
&& !FileUtils.isFileExists("config.properties")) {
21+
PropertyUtils.writeInPropertyFile(args[1]);
22+
}
23+
1624
GetYTVideoInformations getYTVideoInformations = new GetYTVideoInformations(new VideoDaoHibernateImp());
1725
getYTVideoInformations.getYTVideoStatistics(args[0]);
1826

src/main/java/dao/YTUserDaoHibernateImp.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ public List<IYoutubeUser> findAllYTUsersByVideoId(final String videoId){
3535
findAllYTUsers().forEach(iYoutubeUser -> iYoutubeUser.getIVideoInfoList()
3636
.forEach(i -> {if(videoId.equals(i.getVideoId())){ userList.add(iYoutubeUser);}}));
3737

38-
//for(IYoutubeUser iYoutubeUser : findAllYTUsers()){
39-
// for(int i = 0; i < iYoutubeUser.getIVideoInfoList().size(); i++) {
40-
// if (videoId.equals(iYoutubeUser.getIVideoInfoList().get(i).getVideoId())) {
41-
// userList.add(iYoutubeUser);
42-
// }
43-
// }
44-
//}
4538
return userList;
4639
}
4740

src/main/java/util/FileUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ public static File createDirectory(){
1515

1616
return dir;
1717
}
18+
19+
public static boolean isFileExists(String path){
20+
File file = new File(path);
21+
22+
if(file.exists() && !file.isDirectory()) {
23+
return true;
24+
}
25+
26+
return false;
27+
}
1828
}

src/main/java/util/PropertyUtils.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55

66
public class PropertyUtils {
77

8-
public static String readPropertyFile() throws IOException {
9-
ClassLoader loader = Thread.currentThread().getContextClassLoader();
10-
try (InputStream input = loader.getResourceAsStream("config.properties")) {
11-
12-
Properties prop = new Properties();
8+
public static void writeInPropertyFile(final String value) {
9+
try (OutputStream output = new FileOutputStream("config.properties")) {
1310

14-
prop.load(input);
11+
Properties properties = new Properties();
1512

16-
return prop.getProperty("CLIENT.SECRET");
13+
properties.setProperty("CLIENT.SECRET", value);
14+
properties.store(output, null);
1715

18-
} catch (FileNotFoundException fileNotFoundException) {
19-
fileNotFoundException.printStackTrace();
20-
}catch (IOException ioException){
21-
ioException.printStackTrace();
16+
} catch (IOException io) {
17+
io.printStackTrace();
2218
}
23-
return "";
2419
}
20+
21+
public static String readPropertyFile() throws IOException {
22+
Properties properties = new Properties();
23+
properties.load(new FileReader("config.properties"));
24+
25+
return properties.getProperty("CLIENT.SECRET");
26+
}
2527
}
2628

src/main/resources/config.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)