Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-training-project-2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arham Shafiq
java-training-project-2
Commits
363c4a24
Commit
363c4a24
authored
Jul 05, 2022
by
Muhammad Abdul Qadeer Farooqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated
parent
a9828549
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
28 deletions
+91
-28
merged.txt
create-file/merged.txt
+4
-3
pom.xml
user-service/pom.xml
+22
-2
UserService.java
...ce/src/main/java/com/qadeer/user/service/UserService.java
+65
-23
No files found.
create-file/merged.txt
View file @
363c4a24
1, Ahmed, 23, b
usiness, false, hbl, 231234123, fals
e
1, Ahmed, 23, b
anker, false, hbl, 231234123, tru
e
2, Qadeer, 23, job, false, hbl, 231234123, false
2, Qadeer, 23, job, false, hbl, 231234123, false
3, Sahal, 23, job, false, hbl, 231234123, false
3, Sahal, 23, job, false, hbl, 231234123, false
4, Arham, 23, business, false, hbl, 231234123, true
4, Arham, 23, banker, false, hbl, 231234123, arham
5, Naveed, 23, banker, false, hbl, 231234123, false
5, Naveed, 23, job, false, hbl, 231234123, false
user-service/pom.xml
View file @
363c4a24
...
@@ -17,6 +17,13 @@
...
@@ -17,6 +17,13 @@
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
</properties>
</properties>
<dependencies>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.12.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
...
@@ -36,7 +43,12 @@
...
@@ -36,7 +43,12 @@
<artifactId>
validation-api
</artifactId>
<artifactId>
validation-api
</artifactId>
<version>
2.0.1.Final
</version>
<version>
2.0.1.Final
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.11.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<!-- <dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <artifactId>h2</artifactId>-->
...
@@ -57,7 +69,15 @@
...
@@ -57,7 +69,15 @@
</excludes>
</excludes>
</configuration>
</configuration>
</plugin>
</plugin>
</plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
11
</source>
<target>
11
</target>
</configuration>
</plugin>
</plugins>
</build>
</build>
</project>
</project>
user-service/src/main/java/com/qadeer/user/service/UserService.java
View file @
363c4a24
package
com
.
qadeer
.
user
.
service
;
package
com
.
qadeer
.
user
.
service
;
import
com.qadeer.user.model.User
;
import
com.qadeer.user.model.User
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.*
;
import
java.io.*
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.io.FileUtils
;
import
java.io.IOException
;
@Service
@Service
public
class
UserService
{
public
class
UserService
{
...
@@ -38,44 +44,41 @@ public class UserService {
...
@@ -38,44 +44,41 @@ public class UserService {
public
String
updateUserById
(
int
id
,
String
status
)
throws
IOException
{
public
String
updateUserById
(
int
id
,
String
status
)
throws
IOException
{
boolean
flag
=
false
;
boolean
flag
=
false
;
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
"/Users/aqadeer/Desktop/java-training-project-2/create-file/merged.txt"
));
StringBuilder
result
=
new
StringBuilder
();
String
myLine
=
br
.
readLine
();
StringBuilder
myString
=
new
StringBuilder
();
StringBuilder
result
=
new
StringBuilder
();
myString
.
append
(
myLine
);
myString
.
append
(
"\n"
);
while
(
myLine
!=
null
)
{
//java 8
String
contents
=
FileUtils
.
readFileToString
(
new
File
(
"/Users/aqadeer/Desktop/java-training-project-2/create-file/merged.txt"
),
"UTF-8"
);
String
[]
contentArray
=
contents
.
split
(
"\n"
);
for
(
String
x
:
contentArray
)
{
List
<
String
>
myStringList
=
Arrays
.
asList
(
myLine
.
split
(
","
));
List
<
String
>
myStringList
=
Arrays
.
asList
(
x
.
split
(
","
));
int
myId
=
Integer
.
parseInt
(
myStringList
.
get
(
0
));
int
myId
=
Integer
.
parseInt
(
myStringList
.
get
(
0
));
String
profession
=
myStringList
.
get
(
3
).
trim
();
String
profession
=
myStringList
.
get
(
3
).
trim
();
int
x
=
Integer
.
parseInt
(
String
.
valueOf
(
myLine
.
charAt
(
0
)));
if
(
x
==
id
&&
(
profession
.
equals
(
"business"
)
||
profession
.
equals
(
"banker"
)))
{
String
someStr
=
String
.
valueOf
(
myString
).
replaceAll
(
" [^,]*$"
,
" "
+
status
);
if
(
myId
==
id
&&
(
profession
.
equals
(
"business"
)
||
profession
.
equals
(
"banker"
)))
{
String
someStr
=
String
.
valueOf
(
x
).
replaceAll
(
" [^,]*$"
,
" "
+
status
);
result
.
append
(
someStr
);
result
.
append
(
someStr
);
result
.
append
(
"\n"
);
result
.
append
(
"\n"
);
contentArray
=
ArrayUtils
.
remove
(
contentArray
,
0
);
flag
=
true
;
flag
=
true
;
break
;
}
}
else
{
else
{
result
.
append
(
myString
);
result
.
append
(
x
);
result
.
append
(
"\n"
);
contentArray
=
ArrayUtils
.
remove
(
contentArray
,
0
);
}
}
}
myLine
=
br
.
readLine
();
String
finalString
=
String
.
join
(
"\n"
,
contentArray
);
if
(
myLine
==
null
)
{
result
.
append
(
finalString
);
break
;
result
.
append
(
"\n"
);
}
myString
=
new
StringBuilder
();
myString
.
append
(
myLine
);
myString
.
append
(
"\n"
);
}
if
(
flag
)
{
if
(
flag
)
{
PrintWriter
pw
=
new
PrintWriter
(
"/Users/aqadeer/Desktop/java-training-project-2/create-file/merged.txt"
);
PrintWriter
pw
=
new
PrintWriter
(
"/Users/aqadeer/Desktop/java-training-project-2/create-file/merged.txt"
);
int
last
=
result
.
lastIndexOf
(
"\n"
);
if
(
last
>=
0
)
{
result
.
delete
(
last
,
result
.
length
());
}
pw
.
println
(
String
.
valueOf
(
result
));
pw
.
println
(
String
.
valueOf
(
result
));
pw
.
flush
();
pw
.
flush
();
pw
.
close
();
pw
.
close
();
...
@@ -83,4 +86,43 @@ public class UserService {
...
@@ -83,4 +86,43 @@ public class UserService {
}
}
return
"not allowed"
;
return
"not allowed"
;
}
}
// while (myLine != null) {
//
// List<String> myStringList = Arrays.asList(myLine.split(","));
// int myId = Integer.parseInt(myStringList.get(0));
// String profession = myStringList.get(3).trim();
// int x = Integer.parseInt(String.valueOf(myLine.charAt(0)));
// if (x == id && (profession.equals("business") || profession.equals("banker"))) {
// String someStr = String.valueOf(myString).replaceAll(" [^,]*$", " " + status);
// result.append(someStr);
// result.append("\n");
// flag = true;
// }
// else {
// result.append(myString);
//
// }
//
// myLine = br.readLine();
// if (myLine == null) {
// break;
// }
// myString = new StringBuilder();
// myString.append(myLine);
// myString.append("\n");
//
//
// }
// if (flag) {
// PrintWriter pw = new PrintWriter("/Users/aqadeer/Desktop/java-training-project-2/create-file/merged.txt");
// int last = result.lastIndexOf("\n");
// if (last >= 0) { result.delete(last, result.length()); }
// pw.println(String.valueOf(result));
// pw.flush();
// pw.close();
// return "user updated.";
// }
// return "not allowed";
// }
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment