Changeset 5174
- Timestamp:
- 05/09/14 17:17:57 (10 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/pom.xml
r5014 r5174 15 15 16 16 <dependencies> 17 <dependency> 18 <groupId>org.apache.xerces</groupId> 19 <artifactId>xercesImpl</artifactId> 20 <version>2.9.0</version> 21 </dependency> 17 22 <dependency> 18 23 <groupId>javax.servlet</groupId> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java
r5030 r5174 42 42 final static public String INVALID_BODY_EXCEPTION = "Invalide annotation body: both, text and xml options, are null."; 43 43 44 public static String replace(String text, Map<String, String> pairs) {45 String result = (new StringBuilder(text)).toString();46 for (String tempTarget: pairs.keySet()) {47 if ( tempTarget!= null) {48 if (! tempTarget.trim().equals("")) {49 re sult = result.replaceAll(tempTarget, pairs.get(tempTarget));44 public static String replace(String text, Map<String, ?> pairs) { 45 StringBuilder result = new StringBuilder(text); 46 for (String old : pairs.keySet()) { 47 if (old != null) { 48 if (!old.equals("")) { 49 replaceString(result, old, pairs.get(old)); 50 50 } 51 51 } 52 52 } 53 return result; 53 return result.toString(); 54 } 55 56 public static StringBuilder replaceString(StringBuilder source, String oldFragment, Object newObject) { 57 if (oldFragment != null) { 58 int lengthOld = oldFragment.length(); 59 String newFragment; 60 if (newObject != null) { 61 if (newObject instanceof Integer) { 62 newFragment = ((Integer) newObject).toString(); 63 } else { 64 if (newObject instanceof String) { 65 newFragment = (String) newObject; 66 } else { 67 newFragment = newObject.toString(); 68 } 69 } 70 } else { 71 newFragment = " "; 72 } 73 int lengthNew = newFragment.length(); 74 int indexOf = source.indexOf(oldFragment); 75 while (indexOf > 0) { 76 source.delete(indexOf, indexOf + lengthOld); 77 source.insert(indexOf, newFragment); 78 indexOf = source.indexOf(oldFragment, indexOf + lengthNew); 79 } 80 } 81 return source; 54 82 } 55 83 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r5086 r5174 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Helpers; 20 21 import eu.dasish.annotation.backend.NotInDataBaseException; 21 22 import eu.dasish.annotation.backend.dao.ResourceDao; … … 108 109 protected <T> List<T> loggedQuery(String sql, RowMapper<T> rm, Map<String, ?> args) { 109 110 List<T> result = getSimpleJdbcTemplate().query(sql, rm, args); 110 String sqlStatement = replaceInString(sql, args);111 String sqlStatement = Helpers.replace(sql, args); 111 112 logger.debug("\n SQL query: " + sqlStatement + "\n"); 112 113 return result; … … 126 127 protected int loggedUpdate(String sql, Map<String, ?> args) { 127 128 int result = getSimpleJdbcTemplate().update(sql, args); 128 String sqlStatement = replaceInString(sql, args);129 String sqlStatement = Helpers.replace(sql, args); 129 130 logger.debug("\n SQL query: " + sqlStatement + "\n"); 130 131 return result; … … 137 138 } 138 139 139 private String replaceInString(String string, Map<String, ?> map) { 140 String result = (new StringBuilder(string)).toString(); 141 Set<String> keys = map.keySet(); 142 for (String key : keys) { 143 if (map.get(key) != null) { 144 result = result.replaceAll(":" + key, map.get(key).toString()); 145 } else { 146 result = result.replaceAll(":" + key, "null!!"); 147 } 148 } 149 return result; 150 } 151 140 152 141 private <T> String replaceQuestionmarkInString(String string, T arg) { 153 142 String result = (new StringBuilder(string)).toString(); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r5088 r5174 62 62 @Transactional(rollbackFor = {Exception.class}) 63 63 public class AnnotationResource extends ResourceResource { 64 65 66 64 67 65 public void setUriInfo(UriInfo uriInfo) { … … 216 214 @Path("") 217 215 public JAXBElement<ResponseBody> createAnnotation(Annotation annotation) throws IOException { 218 Map params = new HashMap(); 219 params.put("annotation", annotation); 220 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation()); 221 if (result != null) { 222 return (new ObjectFactory()).createResponseBody(result); 223 } else { 224 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 225 } 226 } 216 217 Map params = new HashMap(); 218 params.put("annotation", annotation); 219 ResponseBody result = (ResponseBody) (new RequestWrappers(this)).wrapRequestResource(params, new AddAnnotation()); 220 if (result != null) { 221 return (new ObjectFactory()).createResponseBody(result); 222 } else { 223 return (new ObjectFactory()).createResponseBody(new ResponseBody()); 224 } 225 } 226 227 227 228 228 229 private class AddAnnotation implements ILambda<Map, ResponseBody> { … … 304 305 } 305 306 } 306 307 307 308 @PUT 308 309 @Consumes(MediaType.TEXT_PLAIN) … … 415 416 return genericUpdateDeleteAccess(annotationId, principalId, null); 416 417 } 417 418 419 418 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/JaxbUnmarshallerFactory.java
r5145 r5174 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import java.io.FileInputStream; 21 import java.io.FileNotFoundException; 20 import java.io.BufferedReader; 21 import java.io.InputStreamReader; 22 import java.net.URL; 22 23 import javax.xml.bind.JAXBContext; 23 import javax.xml.bind.JAXBException;24 24 import javax.xml.bind.PropertyException; 25 25 import javax.xml.bind.Unmarshaller; 26 import javax.xml.transform.Source;27 26 import javax.xml.transform.stream.StreamSource; 28 27 import javax.xml.validation.Schema; 29 28 import javax.xml.validation.SchemaFactory; 30 import org.slf4j.Logger;31 import org.slf4j.LoggerFactory;32 import org.xml.sax.SAXException;33 29 34 30 /** … … 42 38 // overwritten by the web.xml's 43 39 // why?? se the bean 44 private static String schemaLocation = "https://svn.clarin.eu/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd";40 private static String schemaLocation = null; 45 41 private static final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema"; 46 42 private static Schema dwanSchema; 47 private final static Logger LOG = LoggerFactory.getLogger(JaxbUnmarshallerFactory.class); 48 private static Source schemaSource = null; 43 private static StreamSource schemaSource = null; 49 44 50 45 public JaxbUnmarshallerFactory() throws Exception { … … 59 54 } 60 55 61 public Unmarshaller createUnmarshaller(Class<?> type) throws JAXBException {56 public Unmarshaller createUnmarshaller(Class<?> type) throws Exception { 62 57 context = JAXBContext.newInstance(type); 63 58 unmarshaller = context.createUnmarshaller(); 64 59 if (dwanSchema == null) { 65 try { 66 FileInputStream inputStream = new FileInputStream("/Users/olhsha/repositories/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd"); 67 schemaSource = new StreamSource(inputStream); 68 unmarshaller.setSchema(getDwanSchema()); 69 } catch (FileNotFoundException e) { 70 LOG.info(e.toString()); 71 } 60 unmarshaller.setSchema(getDwanSchema()); 72 61 } else { 73 62 unmarshaller.setSchema(dwanSchema); … … 76 65 } 77 66 78 public static synchronized Schema getDwanSchema() { 79 try { 80 try { 81 SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); 82 dwanSchema = schemaFactory.newSchema(schemaSource); 83 } catch (SAXException e) { 84 LOG.error("Cannot instantiate schema", e); 85 } 86 } catch (NullPointerException e1) { 87 LOG.error("!!Exception", e1); 88 } 67 public static synchronized Schema getDwanSchema() throws Exception{ 68 69 SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); 70 URL schemaURL = new URL(schemaLocation); 71 InputStreamReader is = new InputStreamReader(schemaURL.openStream()); 72 schemaSource = new StreamSource(is); 73 dwanSchema = schemaFactory.newSchema(schemaSource); 89 74 return dwanSchema; 90 75 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/ResourceJaxbUnmarshallerProvider.java
r5145 r5174 20 20 import javax.ws.rs.ext.ContextResolver; 21 21 import javax.ws.rs.ext.Provider; 22 import javax.xml.bind.JAXBException;23 22 import javax.xml.bind.Unmarshaller; 23 import org.slf4j.Logger; 24 import org.slf4j.LoggerFactory; 24 25 import org.springframework.beans.factory.annotation.Autowired; 25 26 import org.springframework.stereotype.Component; … … 35 36 @Autowired 36 37 private JaxbUnmarshallerFactory jaxbUnmarshallerFactory; 38 private Logger logger = LoggerFactory.getLogger(ResourceJaxbUnmarshallerProvider.class); 37 39 38 40 /* … … 45 47 try { 46 48 return jaxbUnmarshallerFactory.createUnmarshaller(type); 47 48 } catch (JAXBException e) { 49 System.out.println("Cannot create an unmarshaller for type " + type.getCanonicalName()); 49 } catch (Exception e) { 50 logger.error(e.toString()); 50 51 return null; 51 52 } 53 52 54 } 55 56 53 57 } 54 58 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/WEB-INF/web.xml
r5122 r5174 34 34 <context-param> 35 35 <param-name>eu.dasish.annotation.backend.schemaLocation</param-name> 36 <param-value>http://www.dasish.eu/ns/addit https://svn.clarin.eu/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd</param-value> 37 <!-- <param-value>http://www.dasish.eu/ns/addit file:/Users/olhsha/repositories/DASISH/t5.6/schema/trunk/annotator-schema/src/main/target/DASISH-schema.xsd</param-value> --> 36 <param-value>http://lux17.mpi.nl/schemacat/schemas/s15/files/dwan.xsd</param-value> 38 37 </context-param> 39 38 <context-param> -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r5138 r5174 31 31 import java.sql.Timestamp; 32 32 import java.util.ArrayList; 33 import java.util.HashMap; 33 34 import java.util.List; 34 35 import java.util.Map; … … 512 513 513 514 } 515 516 @Test 517 public void helperReplaceString() { 518 System.out.println("test Helpers.ReplaceString"); 519 StringBuilder source = new StringBuilder("va%?&b;v_wa%?&b;w"); 520 String oldFragment = "a%?&b;"; 521 String newFragment = ":;:"; 522 Helpers.replaceString(source, oldFragment, (Object) newFragment); 523 assertEquals(source.toString(), "v:;:v_w:;:w"); 524 } 525 526 @Test 527 public void helperReplace() { 528 System.out.println("test Helpers.Replace"); 529 String source = "va%?&b;v_xy:_wa%?&b;w"; 530 Map<String, String> replacements = new HashMap<String,String>(); 531 replacements.put("a%?&b;", ":;:"); 532 replacements.put("xy:", ":yx"); 533 replacements.put("", ":;:"); 534 String sourceUPD = Helpers.replace(source, replacements); 535 assertEquals(sourceUPD, "v:;:v_:yx_w:;:w"); 536 } 514 537 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.java
r4603 r5174 61 61 sqlString = sqlString.replaceAll(unknownToken, "-- " + unknownToken); 62 62 } 63 //sqlString = sqlString.replaceAll("CACHE 1;", "; -- CACHE 1;"); 64 //sqlString = sqlString.replaceAll("UUID", "text"); 63 65 64 sqlString = sqlString.replaceAll("bytea", "blob"); 66 65 sqlString = sqlString.replaceAll("SERIAL NOT NULL", "INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY"); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r5145 r5174 47 47 import static org.junit.Assert.*; 48 48 import org.junit.Before; 49 import org.junit.Ignore; 49 50 import org.junit.runner.RunWith; 50 51 import org.springframework.beans.factory.annotation.Autowired; … … 181 182 */ 182 183 @Test 184 @Ignore 183 185 public void testCreateAnnotation() throws NotInDataBaseException, IOException{ 184 186
Note: See TracChangeset
for help on using the changeset viewer.