Changeset 3926
- Timestamp:
- 10/31/13 19:18:40 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml
r3722 r3926 96 96 mvn license:format 97 97 98 For more info, see <http://mathieu.carbou.free.fr/p/maven-license-plugin/>.99 -->100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 98 For more info, see <http://mathieu.carbou.free.fr/p/maven-license-plugin/>. 99 --> 100 <groupId>com.mycila.maven-license-plugin</groupId> 101 <artifactId>maven-license-plugin</artifactId> 102 <version>1.9.0</version> 103 <configuration> 104 <header>/src/license-header.txt</header> 105 <strictCheck>false</strictCheck> 106 <properties> 107 <year>${plugin.license.copyrightYear}</year> 108 <organization>${project.organization.name}</organization> 109 </properties> 110 <mapping> 111 <svg>XML_STYLE</svg> 112 <imdi>XML_STYLE</imdi> 113 <cmdi>XML_STYLE</cmdi> 114 </mapping> 115 <excludes> 116 <exclude>nbactions.xml</exclude> 117 <exclude>nb-configuration.xml</exclude> 118 <exclude>**/*.txt</exclude> 119 <exclude>src/main/resources/xml.xsd</exclude> 120 </excludes> 121 </configuration> 122 <executions> 123 <execution> 124 <goals> 125 <goal>check</goal> 126 </goals> 127 </execution> 128 </executions> 129 </plugin> 130 <plugin> 131 <groupId>org.apache.maven.plugins</groupId> 132 <artifactId>maven-javadoc-plugin</artifactId> 133 <version>2.9.1</version> 134 </plugin> 135 </plugins> 136 136 </build> 137 137 <dependencies> 138 <dependency> 139 <groupId>com.sun.jersey</groupId> 140 <artifactId>jersey-servlet</artifactId> 141 <version>${jersey.version}</version> 142 </dependency> 143 <dependency> 144 <groupId>com.sun.jersey</groupId> 145 <artifactId>jersey-json</artifactId> 146 <version>${jersey.version}</version> 147 <scope>test</scope> 148 </dependency> 149 <dependency> 150 <groupId>com.sun.jersey</groupId> 151 <artifactId>jersey-client</artifactId> 152 <version>${jersey.version}</version> 153 <scope>test</scope> 154 </dependency> 155 <dependency> 156 <groupId>com.sun.jersey.jersey-test-framework</groupId> 157 <artifactId>jersey-test-framework-grizzly2</artifactId> 158 <version>${jersey.version}</version> 159 </dependency> 160 <dependency> 161 <groupId>com.sun.jersey.contribs</groupId> 162 <artifactId>jersey-spring</artifactId> 163 <version>${jersey.version}</version> 164 <exclusions> 165 <exclusion> 166 <groupId>org.springframework</groupId> 167 <artifactId>*</artifactId> 168 </exclusion> 169 </exclusions> 170 </dependency> 171 <dependency> 172 <groupId>org.jmock</groupId> 173 <artifactId>jmock-junit4</artifactId> 174 <version>2.5.1</version> 175 <scope>test</scope> 176 </dependency> 177 <dependency> 178 <groupId>org.springframework</groupId> 179 <artifactId>spring-jdbc</artifactId> 180 <version>${spring.version}</version> 181 </dependency> 182 <dependency> 183 <groupId>org.springframework</groupId> 184 <artifactId>spring-web</artifactId> 185 <version>${spring.version}</version> 186 </dependency> 187 <dependency> 188 <groupId>org.hsqldb</groupId> 189 <artifactId>hsqldb</artifactId> 190 <version>2.2.9</version> 191 <scope>test</scope> 192 <classifier>jdk5</classifier> 193 </dependency> 194 <dependency> 195 <groupId>commons-dbcp</groupId> 196 <artifactId>commons-dbcp</artifactId> 197 <version>1.4</version> 198 </dependency> 199 <dependency> 200 <groupId>org.springframework</groupId> 201 <artifactId>spring-test</artifactId> 202 <version>${spring.version}</version> 203 <scope>test</scope> 204 </dependency> 205 <dependency> 206 <groupId>postgresql</groupId> 207 <artifactId>postgresql</artifactId> 208 <version>8.4-702.jdbc4</version> 209 </dependency> 138 <dependency> 139 <groupId>com.sun.jersey</groupId> 140 <artifactId>jersey-servlet</artifactId> 141 <version>${jersey.version}</version> 142 </dependency> 143 <dependency> 144 <groupId>com.sun.jersey</groupId> 145 <artifactId>jersey-json</artifactId> 146 <version>${jersey.version}</version> 147 <scope>test</scope> 148 </dependency> 149 <dependency> 150 <groupId>com.sun.jersey</groupId> 151 <artifactId>jersey-client</artifactId> 152 <version>${jersey.version}</version> 153 <scope>test</scope> 154 </dependency> 155 <dependency> 156 <groupId>com.sun.jersey.jersey-test-framework</groupId> 157 <artifactId>jersey-test-framework-grizzly2</artifactId> 158 <version>${jersey.version}</version> 159 </dependency> 160 <dependency> 161 <groupId>com.sun.jersey.contribs</groupId> 162 <artifactId>jersey-spring</artifactId> 163 <version>${jersey.version}</version> 164 <exclusions> 165 <exclusion> 166 <groupId>org.springframework</groupId> 167 <artifactId>*</artifactId> 168 </exclusion> 169 </exclusions> 170 </dependency> 171 <dependency> 172 <groupId>com.sun.jersey.contribs</groupId> 173 <artifactId>jersey-multipart</artifactId> 174 <version>${jersey.version}</version> 175 </dependency> 176 <dependency> 177 <groupId>org.jmock</groupId> 178 <artifactId>jmock-junit4</artifactId> 179 <version>2.5.1</version> 180 <scope>test</scope> 181 </dependency> 182 <dependency> 183 <groupId>org.springframework</groupId> 184 <artifactId>spring-jdbc</artifactId> 185 <version>${spring.version}</version> 186 </dependency> 187 <dependency> 188 <groupId>org.springframework</groupId> 189 <artifactId>spring-web</artifactId> 190 <version>${spring.version}</version> 191 </dependency> 192 <dependency> 193 <groupId>org.hsqldb</groupId> 194 <artifactId>hsqldb</artifactId> 195 <version>2.2.9</version> 196 <scope>test</scope> 197 <classifier>jdk5</classifier> 198 </dependency> 199 <dependency> 200 <groupId>commons-dbcp</groupId> 201 <artifactId>commons-dbcp</artifactId> 202 <version>1.4</version> 203 </dependency> 204 <dependency> 205 <groupId>org.springframework</groupId> 206 <artifactId>spring-test</artifactId> 207 <version>${spring.version}</version> 208 <scope>test</scope> 209 </dependency> 210 <dependency> 211 <groupId>postgresql</groupId> 212 <artifactId>postgresql</artifactId> 213 <version>8.4-702.jdbc4</version> 214 </dependency> 210 215 </dependencies> 211 216 <properties> 212 213 214 215 216 217 217 <jersey.version>1.17.1</jersey.version> 218 <spring.version>3.0.0.RELEASE</spring.version> 219 <glassfish.version>3.1.1</glassfish.version> 220 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 221 <netbeans.hint.license>gpl20</netbeans.hint.license> 222 <plugin.license.copyrightYear>2013</plugin.license.copyrightYear> 218 223 </properties> 219 224 </project> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
r3916 r3926 23 23 import java.io.InputStream; 24 24 import java.lang.String; 25 import java.sql.Blob;26 import java.sql.Connection;27 import java.sql.DriverManager;28 25 import java.sql.ResultSet; 29 26 import java.sql.SQLException; 27 import java.sql.Types; 30 28 import java.util.HashMap; 31 29 import java.util.List; … … 34 32 import javax.sql.DataSource; 35 33 import org.springframework.jdbc.core.RowMapper; 34 import org.springframework.jdbc.core.support.SqlLobValue; 36 35 37 36 /** … … 114 113 public Number addCachedRepresentation(CachedRepresentationInfo cachedInfo, InputStream streamCached) { 115 114 try { 116 try { 117 Blob blob = writeInputStreamToBlob(streamCached); 118 UUID externalIdentifier = UUID.randomUUID(); 119 Map<String, Object> params = new HashMap<String, Object>(); 120 params.put("externalId", externalIdentifier.toString()); 121 params.put("mime_type", cachedInfo.getMimeType()); 122 params.put("tool", cachedInfo.getTool()); 123 params.put("type", cachedInfo.getType()); 124 params.put("blob", blob); 125 StringBuilder sql = new StringBuilder("INSERT INTO "); 126 sql.append(cachedRepresentationTableName).append("(").append(external_id).append(",").append(mime_type).append(",").append(tool).append(",").append(type_).append(",").append(file_).append(" ) VALUES (:externalId, :mime_type, :tool, :type, :blob)"); 127 final int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 128 return (affectedRows > 0 ? getInternalID(externalIdentifier) : null); 129 } catch (SQLException sqle) { 130 return null; 131 } 115 UUID externalIdentifier = UUID.randomUUID(); 116 Map<String, Object> params = new HashMap<String, Object>(); 117 params.put("externalId", externalIdentifier.toString()); 118 params.put("mime_type", cachedInfo.getMimeType()); 119 params.put("tool", cachedInfo.getTool()); 120 params.put("type", cachedInfo.getType()); 121 params.put("blob", getBytesForBlob(streamCached)); 122 StringBuilder sql = new StringBuilder("INSERT INTO "); 123 sql.append(cachedRepresentationTableName).append("(").append(external_id).append(",").append(mime_type).append(",").append(tool).append(",").append(type_).append(",").append(file_).append(" ) VALUES (:externalId, :mime_type, :tool, :type, :blob)"); 124 final int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params); 125 return (affectedRows > 0 ? getInternalID(externalIdentifier) : null); 126 132 127 } catch (IOException ioe) { 133 128 return null; … … 148 143 } 149 144 150 // HELPERS 151 private Blob writeInputStreamToBlob(InputStream in) throws IOException, SQLException { 152 Connection con = getConnection(); 153 //Connection con = DriverManager.getConnection("jdbc:postgresql:annotator", "dasish", "dasish"); 154 Blob blob = con.createBlob(); 155 byte[] buffer = new byte[8192]; 156 long pos = 0; 157 int bytesRead = 0; 158 while ((bytesRead = in.read(buffer, 0, 8192)) != -1) { 159 int bytesWritten = blob.setBytes(pos, buffer, 0, bytesRead); 160 pos = pos + bytesWritten; 145 /////////// HELPERS /////////////// 146 private byte[] getBytesForBlob(InputStream iStream) throws IOException { 147 int max_buffer_size = 1024 * 1024 * 3; 148 byte[] buffer = new byte[max_buffer_size]; 149 int bytesRead = iStream.read(buffer); 150 byte[] result = new byte[bytesRead]; 151 for (int i = 0; i < bytesRead; i++) { 152 result[i] = buffer[i]; 161 153 } 162 return blob;154 return result; 163 155 } 164 156 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/TargetResource.java
r3916 r3926 24 24 import eu.dasish.annotation.schema.ReferenceList; 25 25 import eu.dasish.annotation.schema.Target; 26 import java.io.ByteArrayInputStream; 26 import java.io.File; 27 import java.io.FileInputStream; 28 import java.io.FileNotFoundException; 29 import java.io.InputStream; 27 30 import java.sql.SQLException; 28 31 import java.util.UUID; … … 41 44 import org.springframework.beans.factory.annotation.Autowired; 42 45 import org.springframework.stereotype.Component; 46 47 import com.sun.jersey.multipart.FormDataParam; 43 48 44 49 /** … … 105 110 } 106 111 112 107 113 @POST 108 //@Consumes("multipart/mixed") 109 @Consumes(MediaType.APPLICATION_XML) 114 @Consumes("multipart/mixed") 110 115 @Produces(MediaType.APPLICATION_XML) 111 116 @Path("{targetid: "+BackendConstants.regExpIdentifier +"}/cached") 112 public JAXBElement<CachedRepresentationInfo> postCached(@PathParam("targetid") String targetIdentifier, CachedRepresentationInfo metadata) throws SQLException {117 public JAXBElement<CachedRepresentationInfo> postCached(@PathParam("targetid") String targetIdentifier, InputStream inputStream, CachedRepresentationInfo metadata) throws SQLException { 113 118 dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); 114 119 final Number targetID = dbIntegrityService.getTargetInternalIdentifier(UUID.fromString(targetIdentifier)); 115 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, metadata, new ByteArrayInputStream("aaa".getBytes())); 120 121 final Number[] respondDB = dbIntegrityService.addCachedForTarget(targetID, metadata, inputStream); 116 122 final CachedRepresentationInfo cachedInfo = dbIntegrityService.getCachedRepresentationInfo(respondDB[1]); 117 123 return new ObjectFactory().createCashedRepresentationInfo(cachedInfo); 124 118 125 } 126 119 127 120 128 }
Note: See TracChangeset
for help on using the changeset viewer.