diff --git a/Soap/.gitignore b/Soap/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Soap/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Soap/.idea/.gitignore b/Soap/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Soap/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Soap/.idea/libraries/javax_jws_api.xml b/Soap/.idea/libraries/javax_jws_api.xml new file mode 100644 index 0000000..56f09d7 --- /dev/null +++ b/Soap/.idea/libraries/javax_jws_api.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Soap/.idea/libraries/javax_xml_ws_jaxws_api.xml b/Soap/.idea/libraries/javax_xml_ws_jaxws_api.xml new file mode 100644 index 0000000..b473685 --- /dev/null +++ b/Soap/.idea/libraries/javax_xml_ws_jaxws_api.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Soap/.idea/libraries/sun_xml_ws_rt.xml b/Soap/.idea/libraries/sun_xml_ws_rt.xml new file mode 100644 index 0000000..7c0aa0c --- /dev/null +++ b/Soap/.idea/libraries/sun_xml_ws_rt.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Soap/.idea/misc.xml b/Soap/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/Soap/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Soap/.idea/modules.xml b/Soap/.idea/modules.xml new file mode 100644 index 0000000..a932d29 --- /dev/null +++ b/Soap/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Soap/.idea/vcs.xml b/Soap/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Soap/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Soap/Soap.iml b/Soap/Soap.iml new file mode 100644 index 0000000..f72f07e --- /dev/null +++ b/Soap/Soap.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Soap/src/Main.java b/Soap/src/Main.java new file mode 100644 index 0000000..930198c --- /dev/null +++ b/Soap/src/Main.java @@ -0,0 +1,15 @@ +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + System.out.println("i = " + i); + } + } +} \ No newline at end of file diff --git a/Soap/src/com/soapsoapsoap/User.java b/Soap/src/com/soapsoapsoap/User.java new file mode 100644 index 0000000..3c955d9 --- /dev/null +++ b/Soap/src/com/soapsoapsoap/User.java @@ -0,0 +1,49 @@ +package com.soapsoapsoap; + +import java.util.HashMap; +import java.util.Map; + +public class User { + private int id; + private String name; + private String email; + private Map scores; + + public User(int id, String name, String email) { + this.id = id; + this.name = name; + this.email = email; + this.scores = new HashMap<>(); + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public Map getScores() { + return scores; + } + + public void addScore(String activity, double score) { + scores.put(activity, score); + } + + public double calculateAverageScore() { + if (scores.isEmpty()) { + return 0.0; + } + double sum = 0; + for (double score : scores.values()) { + sum += score; + } + return sum / scores.size(); + } +} diff --git a/Soap/src/com/soapsoapsoap/UserSOAPService.java b/Soap/src/com/soapsoapsoap/UserSOAPService.java new file mode 100644 index 0000000..eb1ef1e --- /dev/null +++ b/Soap/src/com/soapsoapsoap/UserSOAPService.java @@ -0,0 +1,18 @@ +package com.soapsoapsoap; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.jws.soap.SOAPBinding.Style; +import java.util.HashMap; +import java.util.Map; + +@WebService +@SOAPBinding(style = Style.RPC) +public interface UserSOAPService { + @WebMethod String[] getUsersList(); + @WebMethod String getUserById(int id); + @WebMethod double calculateAverageScore(int userId); + @WebMethod boolean addScore(int userId, String activity, double score); + @WebMethod String[] findActivitiesByScore(String minScoreOperator, double minScore); +} diff --git a/Soap/src/com/soapsoapsoap/UserSOAPServiceImpl.java b/Soap/src/com/soapsoapsoap/UserSOAPServiceImpl.java new file mode 100644 index 0000000..ca79b94 --- /dev/null +++ b/Soap/src/com/soapsoapsoap/UserSOAPServiceImpl.java @@ -0,0 +1,89 @@ +package com.soapsoapsoap; + +import javax.jws.WebService; +import java.util.HashMap; +import java.util.Map; +import java.util.ArrayList; +import java.util.List; + +@WebService(endpointInterface = "com.soapsoapsoap.UserSOAPService") +public class UserSOAPServiceImpl implements UserSOAPService { + private static Map usersDb = new HashMap<>(); + + static { + initializeData(); + } + + private static void initializeData() { + User u1 = new User(1, "Foo", "foo@example.com"); + u1.addScore("Activity 1", 80.5); + u1.addScore("Activity 2", 90.0); + u1.addScore("Activity 3", 75.0); + + User u2 = new User(2, "Bar", "bar@example.com"); + u2.addScore("Activity 1", 65.5); + u2.addScore("Activity 2", 70.0); + u2.addScore("Activity 3", 85.0); + + User u3 = new User(3, "Baz", "baz@example.com"); + u3.addScore("Activity 1", 95.0); + u3.addScore("Activity 2", 85.5); + u3.addScore("Activity 3", 80.0); + + usersDb.put(u1.getId(), u1); + usersDb.put(u2.getId(), u2); + usersDb.put(u3.getId(), u3); + } + + public String[] getUsersList() { + List result = new ArrayList<>(); + for (User user : usersDb.values()) { + result.add(user.getId() + ": " + user.getName() + " (" + user.getEmail() + ")"); + } + return result.toArray(new String[0]); + } + + public String getUserById(int id) { + User user = usersDb.get(id); + if (user != null) { + StringBuilder scoresStr = new StringBuilder(); + for (Map.Entry entry : user.getScores().entrySet()) { + scoresStr.append(entry.getKey()).append(": ").append(entry.getValue()).append(", "); + } + return "ID: " + user.getId() + ", Name: " + user.getName() + ", Email: " + user.getEmail() + ", Scores: " + scoresStr.toString(); + } + return "User not found"; + } + + public double calculateAverageScore(int userId) { + User user = usersDb.get(userId); + if (user != null) { + return user.calculateAverageScore(); + } + return 0.0; + } + + public boolean addScore(int userId, String activity, double score) { + User user = usersDb.get(userId); + if (user != null) { + user.addScore(activity, score); + return true; + } + return false; + } + + public String[] findActivitiesByScore(String minScoreOperator, double minScore) { + List results = new ArrayList<>(); + for (User user : usersDb.values()) { + for (Map.Entry entry : user.getScores().entrySet()) { + double score = entry.getValue(); + if ((">".equals(minScoreOperator) && score > minScore) || + (">=".equals(minScoreOperator) && score >= minScore) || + ("=".equals(minScoreOperator) && score == minScore)) { + results.add(entry.getKey() + ": " + score + " (User: " + user.getName() + ")"); + } + } + } + return results.toArray(new String[0]); + } +} \ No newline at end of file diff --git a/Soap/src/com/soapsoapsoap/UserSOAPServicePublisher.java b/Soap/src/com/soapsoapsoap/UserSOAPServicePublisher.java new file mode 100644 index 0000000..deb8619 --- /dev/null +++ b/Soap/src/com/soapsoapsoap/UserSOAPServicePublisher.java @@ -0,0 +1,9 @@ +package com.soapsoapsoap; + +import javax.xml.ws.Endpoint; + +public class UserSOAPServicePublisher { + public static void main(String[] args) { + Endpoint.publish("http://localhost:7779/ws/user", new UserSOAPServiceImpl()); + } +} \ No newline at end of file