@@ -10,7 +10,6 @@ |
package d.crlmod.rusle2; |
|
import crlmod.ServiceResources; |
-import static crlmod.ServiceResources.CR_LMOD_2018_ID; |
import static crlmod.ServiceResources.CR_LMOD_R2; |
import csip.ModelDataService; |
import csip.annotations.Description; |
@@ -22,12 +21,25 @@ |
import csip.api.server.ServiceException; |
import csip.utils.JSONUtils; |
import java.sql.Connection; |
+import java.sql.DriverManager; |
import java.sql.PreparedStatement; |
import java.sql.ResultSet; |
+import java.sql.SQLException; |
import java.sql.Statement; |
import java.util.ArrayList; |
import java.util.List; |
+import java.util.logging.Level; |
+import java.util.logging.Logger; |
+import javax.servlet.http.HttpServletRequest; |
+import javax.ws.rs.GET; |
import javax.ws.rs.Path; |
+import javax.ws.rs.Produces; |
+import javax.ws.rs.core.Context; |
+import javax.ws.rs.core.MediaType; |
+import javax.ws.rs.core.MultivaluedMap; |
+import javax.ws.rs.core.Response; |
+import javax.ws.rs.core.UriInfo; |
+import org.apache.http.client.HttpResponseException; |
import org.codehaus.jettison.json.JSONArray; |
|
/** |
@@ -179,8 +191,8 @@ |
query += ((add) ? " AND " : " ") + buildPreparedWhereLikeList("name", partial_names); |
add = true; |
} |
- query += " ORDER BY path,name;"; |
- |
+ query += " ORDER BY path,name;"; |
+ |
try (Connection conn = getConnection(); PreparedStatement stmnt = conn.prepareStatement(query)) { |
int counter = 1; |
|
@@ -292,4 +304,60 @@ |
return result; |
} |
} |
+ |
+ @GET |
+ @Produces(MediaType.APPLICATION_XML) |
+ public Response fetchFile(@Context UriInfo uriInfo, |
+ @Context HttpServletRequest httpReq){ |
+ |
+ String requestString = httpReq.getQueryString(); |
+ MultivaluedMap<String, String> requestMap = uriInfo.getQueryParameters(); |
+ |
+ if ((null != requestMap) && (requestMap.size() > 0)) { |
+ if (requestMap.containsKey("path")) { |
+ String path = requestMap.getFirst("path").replaceAll("//", "/").replaceAll("//", "/"); |
+ String name = path.substring(path.lastIndexOf("/") + 1); |
+ path = path.substring(0, path.lastIndexOf("/")); |
+ path = path.replaceAll("/", "\\"); |
+ |
+ String query = "SELECT xmlData FROM R2_Data WHERE path=? AND name=?"; |
+ try (Connection conn = createDataSource(); PreparedStatement stmnt = conn.prepareStatement(query)) { |
+ stmnt.setString(1, path); |
+ stmnt.setString(2, name); |
+ |
+ ResultSet results = stmnt.executeQuery(); |
+ |
+ while (results.next()) { |
+ return Response.status(Response.Status.OK) |
+ .entity(results.getString("xmlData")) |
+ .build(); |
+ } |
+ |
+ return Response.status(Response.Status.NOT_FOUND) |
+ .build(); |
+ } catch (ClassNotFoundException | SQLException ex) { |
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR) |
+ .entity(ex.getMessage()) |
+ .build(); |
+ } |
+ } |
+ return Response.status(Response.Status.NOT_FOUND) |
+ .build(); |
+ } |
+ |
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR) |
+ .build(); |
+ } |
+ |
+ private static synchronized Connection createDataSource() throws ClassNotFoundException, SQLException { |
+ Connection connection = null; |
+ |
+ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); |
+ //System.out.println("Driver was loaded for: com.microsoft.sqlserver.jdbc.SQLServerDriver"); |
+ connection = DriverManager.getConnection("jdbc:sqlserver://129.82.20.129:1433;databaseName=CR_LMOD_2022_step_r2;user=sa;password=csurams#1"); |
+ |
+ //System.out.println("Connection to the local Conservation Resources DB Service was successful\n================================================================================\n"); |
+ connection.setAutoCommit(true); |
+ return connection; |
+ } |
} |