Changeset 4130
- Timestamp:
- 2010-07-09 12:18:02 (3 years ago)
- Location:
- projects/lily/trunk
- Files:
-
- 19 edited
-
README.txt (modified) (2 diffs)
-
indexer/pom.xml (modified) (2 diffs)
-
pom.xml (modified) (1 diff)
-
process/server/conf/hbase/hbase.xml (modified) (1 diff)
-
process/server/conf/repository/repository.xml (modified) (1 diff)
-
repo-util/src/main/java/org/lilycms/repoutil/JsonUtil.java (modified) (1 diff)
-
repository/api/src/main/java/org/lilycms/repository/api/FieldTypeNotFoundException.java (modified) (2 diffs)
-
repository/api/src/main/java/org/lilycms/repository/api/Record.java (modified) (1 diff)
-
repository/impl/src/main/avro/lily.avpr (modified) (1 diff)
-
repository/impl/src/main/java/org/lilycms/repository/avro/AvroConverter.java (modified) (3 diffs)
-
repository/impl/src/main/java/org/lilycms/repository/impl/HBaseTypeManager.java (modified) (1 diff)
-
repository/impl/src/main/java/org/lilycms/repository/impl/IdRecordImpl.java (modified) (1 diff)
-
repository/impl/src/main/java/org/lilycms/repository/impl/RecordImpl.java (modified) (2 diffs)
-
tools/import/sample.json (modified) (1 diff)
-
tools/import/src/main/java/org/lilycms/tools/import_/DefaultImportListener.java (modified) (2 diffs)
-
tools/import/src/main/java/org/lilycms/tools/import_/EntityType.java (modified) (1 diff)
-
tools/import/src/main/java/org/lilycms/tools/import_/ImportListener.java (modified) (1 diff)
-
tools/import/src/main/java/org/lilycms/tools/import_/ImportTool.java (modified) (2 diffs)
-
tools/import/src/main/java/org/lilycms/tools/import_/JsonImportTool.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
projects/lily/trunk/README.txt
r4111 r4130 14 14 ------------- 15 15 16 Download Solr 1.4. 0from http://lucene.apache.org/solr/ and extract it somewhere.16 Download Solr 1.4.1 from http://lucene.apache.org/solr/ and extract it somewhere. 17 17 18 18 Configuring settings.xml … … 30 30 31 31 <properties> 32 <solr.war>/ home/bruno/projects/lily-trunk/deps/apache-solr-1.4.0/dist/apache-solr-1.4.0.war</solr.war>32 <solr.war>/path/to/apache-solr-1.4.1/dist/apache-solr-1.4.1.war</solr.war> 33 33 </properties> 34 34 </profile> -
projects/lily/trunk/indexer/pom.xml
r4101 r4130 77 77 <groupId>org.apache.solr</groupId> 78 78 <artifactId>solr-solrj</artifactId> 79 <version>1.4. 0</version>79 <version>1.4.1</version> 80 80 </dependency> 81 81 … … 83 83 <groupId>org.apache.solr</groupId> 84 84 <artifactId>solr-core</artifactId> 85 <version>1.4. 0</version>85 <version>1.4.1</version> 86 86 <scope>test</scope> 87 87 <exclusions> -
projects/lily/trunk/pom.xml
r4126 r4130 23 23 24 24 <properties> 25 <hbase.version>0.21.0-r9 59305</hbase.version>25 <hbase.version>0.21.0-r962435</hbase.version> 26 26 <!-- When changing the hbase version, also change the hadoop version below to match 27 27 what is in HBase's pom.xml --> -
projects/lily/trunk/process/server/conf/hbase/hbase.xml
r4114 r4130 2 2 <hbase xmlns:conf="http://kauriproject.org/configuration" 3 3 conf:inherit="shallow"> 4 <!--5 4 <zookeeperQuorum>localhost</zookeeperQuorum> 6 5 <zookeeperClientPort>2181</zookeeperClientPort> 7 -->8 6 </hbase> -
projects/lily/trunk/process/server/conf/repository/repository.xml
r4114 r4130 2 2 <repository xmlns:conf="http://kauriproject.org/configuration" 3 3 conf:inherit="shallow"> 4 <!--5 4 <zookeeperConnectString>localhost:2181</zookeeperConnectString> 6 -->7 5 8 6 <!-- Filesystem to use to store blobs --> -
projects/lily/trunk/repo-util/src/main/java/org/lilycms/repoutil/JsonUtil.java
r4125 r4130 41 41 } 42 42 43 public static boolean getBoolean(JsonNode node, String prop) throws JsonFormatException { 44 if (node.get(prop) == null) { 45 throw new JsonFormatException("Missing required property: " + prop); 46 } 47 if (!node.get(prop).isBoolean()) { 48 throw new JsonFormatException("Not a string property: " + prop); 49 } 50 return node.get(prop).getBooleanValue(); 51 } 52 43 53 public static int getInt(JsonNode node, String prop, int defaultValue) throws JsonFormatException { 44 54 if (node.get(prop) == null) { -
projects/lily/trunk/repository/api/src/main/java/org/lilycms/repository/api/FieldTypeNotFoundException.java
r4116 r4130 22 22 23 23 private final String id; 24 private final QName name; 24 25 private final Long version; 25 26 26 27 public FieldTypeNotFoundException(String id, Long version) { 27 28 this.id = id; 29 this.name = null; 28 30 this.version = version; 29 31 } 30 32 33 public FieldTypeNotFoundException(QName name, Long version) { 34 this.id = null; 35 this.name = name; 36 this.version = version; 37 } 38 31 39 public String getId() { 32 40 return id; 33 41 } 34 42 43 public QName getName() { 44 return name; 45 } 46 35 47 public Long getVersion() { 36 48 return version; … … 41 53 StringBuilder stringBuilder = new StringBuilder(); 42 54 stringBuilder.append("FieldType <"); 43 stringBuilder.append(id );55 stringBuilder.append(id != null ? id : name); 44 56 stringBuilder.append("> "); 45 57 if (version != null) { -
projects/lily/trunk/repository/api/src/main/java/org/lilycms/repository/api/Record.java
r4076 r4130 161 161 162 162 boolean equals(Object obj); 163 164 /** 165 * Compares the two records, ignoring some aspects. This method is intended to compare 166 * a record loaded from the repository with a newly instantiated one in which some things 167 * are typically not supplied. 168 * 169 * <p>The aspects which are ignored are: 170 * <ul> 171 * <li>the version 172 * <li>the record types: only the name of the non-versioned record type is compared, if 173 * it is not null in both. The version of the record type is not compared. 174 * </ul> 175 */ 176 boolean softEquals(Object obj); 163 177 } -
projects/lily/trunk/repository/impl/src/main/avro/lily.avpr
r4122 r4130 179 179 "type": "error", 180 180 "fields": [ 181 {"name": "id", "type": "string"}, 181 {"name": "id", "type": ["string", "null"]}, 182 {"name": "name", "type": ["AvroQName", "null"]}, 182 183 {"name": "version", "type": "long"}, 183 184 {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} -
projects/lily/trunk/repository/impl/src/main/java/org/lilycms/repository/avro/AvroConverter.java
r4123 r4130 248 248 249 249 public AvroQName convert(QName name) { 250 if (name == null) 251 return null; 252 250 253 AvroQName avroQName = new AvroQName(); 251 254 if (name.getNamespace() != null) { … … 328 331 public AvroFieldTypeNotFoundException convert(FieldTypeNotFoundException exception) { 329 332 AvroFieldTypeNotFoundException avroException = new AvroFieldTypeNotFoundException(); 330 avroException.id = new Utf8(exception.getId()); 333 if (exception.getId() != null) 334 avroException.id = new Utf8(exception.getId()); 335 if (exception.getName() != null) 336 avroException.name = convert(exception.getName()); 331 337 Long version = exception.getVersion(); 332 338 if (version != null) { … … 362 368 363 369 public FieldTypeNotFoundException convert(AvroFieldTypeNotFoundException avroException) { 364 FieldTypeNotFoundException exception = new FieldTypeNotFoundException(convert(avroException.id), avroException.version); 370 FieldTypeNotFoundException exception; 371 if (avroException.id != null) { 372 exception = new FieldTypeNotFoundException(convert(avroException.id), avroException.version); 373 } else { 374 exception = new FieldTypeNotFoundException(convert(avroException.name), avroException.version); 375 } 365 376 restoreCauses(avroException.remoteCauses, exception); 366 377 return exception; -
projects/lily/trunk/repository/impl/src/main/java/org/lilycms/repository/impl/HBaseTypeManager.java
r4116 r4130 495 495 // TODO the below is a temporary fix, should probably be fixed in getFieldTypeFromCache 496 496 if (fieldType == null) { 497 throw new FieldTypeNotFoundException( "todo", 1L);497 throw new FieldTypeNotFoundException(name, 1L); 498 498 } 499 499 return fieldType; -
projects/lily/trunk/repository/impl/src/main/java/org/lilycms/repository/impl/IdRecordImpl.java
r4076 r4130 137 137 throw new UnsupportedOperationException("IdRecordImpl does not support equals."); 138 138 } 139 140 public boolean softEquals(Object obj) { 141 throw new UnsupportedOperationException("IdRecordImpl does not support softEquals."); 142 } 139 143 } -
projects/lily/trunk/repository/impl/src/main/java/org/lilycms/repository/impl/RecordImpl.java
r4084 r4130 164 164 @Override 165 165 public boolean equals(Object obj) { 166 if (!softEquals(obj)) 167 return false; 168 169 RecordImpl other = (RecordImpl) obj; 170 171 if (recordTypeIds == null) { 172 if (other.recordTypeIds != null) 173 return false; 174 } else if (!recordTypeIds.equals(other.recordTypeIds)) { 175 return false; 176 } 177 178 if (recordTypeVersions == null) { 179 if (other.recordTypeVersions != null) 180 return false; 181 } else if (!recordTypeVersions.equals(other.recordTypeVersions)) { 182 return false; 183 } 184 185 if (version == null) { 186 if (other.version != null) 187 return false; 188 } else if (!version.equals(other.version)) { 189 return false; 190 } 191 192 return true; 193 } 194 195 public boolean softEquals(Object obj) { 166 196 if (this == obj) 167 197 return true; … … 171 201 return false; 172 202 RecordImpl other = (RecordImpl) obj; 203 173 204 if (fields == null) { 174 205 if (other.fields != null) 175 206 return false; 176 } else if (!fields.equals(other.fields)) 177 return false; 207 } else if (!fields.equals(other.fields)) { 208 return false; 209 } 210 178 211 if (fieldsToDelete == null) { 179 212 if (other.fieldsToDelete != null) 180 213 return false; 181 } else if (!fieldsToDelete.equals(other.fieldsToDelete)) 182 return false; 214 } else if (!fieldsToDelete.equals(other.fieldsToDelete)) { 215 return false; 216 } 217 183 218 if (id == null) { 184 219 if (other.id != null) 185 220 return false; 186 } else if (!id.equals(other.id)) 187 return false; 188 if (recordTypeIds == null) { 189 if (other.recordTypeIds != null) 190 return false; 191 } else if (!recordTypeIds.equals(other.recordTypeIds)) 192 return false; 193 if (recordTypeVersions == null) { 194 if (other.recordTypeVersions != null) 195 return false; 196 } else if (!recordTypeVersions.equals(other.recordTypeVersions)) 197 return false; 198 if (version == null) { 199 if (other.version != null) 200 return false; 201 } else if (!version.equals(other.version)) 202 return false; 221 } else if (!id.equals(other.id)) { 222 return false; 223 } 224 225 String nonVersionedRT1 = recordTypeIds.get(Scope.NON_VERSIONED); 226 String nonVersionedRT2 = other.recordTypeIds.get(Scope.NON_VERSIONED); 227 228 if (nonVersionedRT1 != null && nonVersionedRT2 != null && !nonVersionedRT1.equals(nonVersionedRT2)) { 229 return false; 230 } 231 203 232 return true; 204 233 } -
projects/lily/trunk/tools/import/sample.json
r4114 r4130 1 /* 2 This is a sample input file for the import tool. 3 4 The syntax is not limited to strict json: unquoted property names 5 and comments are allowed. 6 */ 1 7 { 2 "namespaces": [3 { "prefix": "sample", "uri": "org.lilycms.tools.import_.sample"}8 namespaces: [ 9 { prefix: "sample", uri: "org.lilycms.tools.import_.sample"} 4 10 ], 5 "fieldTypes": [11 fieldTypes: [ 6 12 { 7 "name": "sample:field1",8 "valueType": { "primitive": "STRING" },9 "scope": "versioned"13 name: "sample:stringfield", 14 valueType: { "primitive": "STRING" }, 15 scope: "versioned" 10 16 }, 11 17 { 12 "name": "sample:field2", 13 "valueType": { "primitive": "STRING" }, 14 "scope": "non_versioned" 18 name: "sample:multiValueString", 19 valueType: { "primitive": "STRING", multiValue: true }, 20 scope: "non_versioned" 21 }, 22 { 23 name: "sample:intfield", 24 valueType: { "primitive": "INTEGER" }, 25 scope: "non_versioned" 26 }, 27 { 28 name: "sample:longfield", 29 valueType: { "primitive": "LONG" }, 30 scope: "non_versioned" 31 }, 32 { 33 name: "sample:booleanfield", 34 valueType: { "primitive": "BOOLEAN" }, 35 scope: "non_versioned" 36 }, 37 { 38 name: "sample:linkfield", 39 valueType: { "primitive": "LINK" }, 40 scope: "non_versioned" 41 }, 42 { 43 name: "sample:datefield", 44 valueType: { "primitive": "DATE" }, 45 scope: "non_versioned" 46 }, 47 { 48 name: "sample:datetimefield", 49 valueType: { "primitive": "DATETIME" }, 50 scope: "non_versioned" 15 51 } 16 52 ], 17 "recordTypes": [53 recordTypes: [ 18 54 { 19 "name": "Book",20 "fields": [21 { "name": "sample:field1", "mandatory": false },22 { "name": "sample:field2", "mandatory": false }55 name: "MiscFields", 56 fields: [ 57 {name: "sample:field1", mandatory: false }, 58 {name: "sample:field2", mandatory: false } 23 59 ] 24 60 } 25 61 ], 26 "records": [ 27 {"type": "Book", "sample:field1": "My first document."}, 28 {"type": "Book", "sample:field1": "My second document.", "sample:field2": "some more data"} 62 records: [ 63 { 64 type: "MiscFields", 65 "sample:stringfield": "My first document.", 66 "sample:multiValueString": ["first", "second", "third"], 67 "sample:intfield": 23, 68 "sample:longfield": 242, 69 "sample:datefield": "2010-07-09", 70 "sample:datetimefield": "2010-07-09T14:04:46", 71 "sample:booleanfield": true 72 }, 73 { 74 type: "MiscFields", 75 id: "zoo", 76 "sample:stringfield": "A document with a user-defined ID" 77 }, 78 { 79 type: "MiscFields", 80 "sample:stringfield": "A document with a link field", 81 "sample:linkfield": "USER.zoo" 82 } 29 83 ] 30 84 } -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/DefaultImportListener.java
r4125 r4130 20 20 } 21 21 22 public void existsAndEqual(EntityType entityType, String entityName ) {23 out.println(String.format("%1$s already exists and is equal: %2$s", toText(entityType), entityName));22 public void existsAndEqual(EntityType entityType, String entityName, String entityId) { 23 out.println(String.format("%1$s already exists and is equal: %2$s", toText(entityType), id(entityName, entityId))); 24 24 } 25 25 26 public void updated(EntityType entityType, String entityName, String entityId) { 27 out.println(String.format("%1$s updated: %2$s", toText(entityType), entityName)); 26 public void updated(EntityType entityType, String entityName, String entityId, long version) { 27 if (entityType == EntityType.RECORD || entityType == EntityType.RECORD_TYPE) { 28 out.println(String.format("%1$s updated: %2$s (version %3$s)", toText(entityType), id(entityName, entityId), version)); 29 } else { 30 out.println(String.format("%1$s updated: %2$s", toText(entityType), id(entityName, entityId))); 31 } 28 32 } 29 33 30 34 public void created(EntityType entityType, String entityName, String entityId) { 31 out.println(String.format("%1$s created: %2$s", toText(entityType), entityName)); 35 out.println(String.format("%1$s created: %2$s", toText(entityType), id(entityName, entityId))); 36 } 37 38 private String id(String entityName, String entityId) { 39 if (entityName != null) { 40 return entityName; 41 } else { 42 return entityId; 43 } 32 44 } 33 45 … … 41 53 entityTypeName = "Record type"; 42 54 break; 55 case RECORD: 56 entityTypeName = "Record"; 57 break; 43 58 default: 44 59 throw new RuntimeException("Unexpected entity type: " + entityType); -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/EntityType.java
r4125 r4130 2 2 3 3 public enum EntityType { 4 FIELD_TYPE, RECORD_TYPE 4 FIELD_TYPE, RECORD_TYPE, RECORD 5 5 } -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/ImportListener.java
r4125 r4130 5 5 throws ImportConflictException; 6 6 7 void existsAndEqual(EntityType entityType, String entityName );7 void existsAndEqual(EntityType entityType, String entityName, String entityId); 8 8 9 void updated(EntityType entityType, String entityName, String entityId );9 void updated(EntityType entityType, String entityName, String entityId, long version); 10 10 11 11 void created(EntityType entityType, String entityName, String entityId); -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/ImportTool.java
r4125 r4130 43 43 44 44 // everything equal, skip it 45 importListener.existsAndEqual(EntityType.FIELD_TYPE, newFieldType.getName().toString() );45 importListener.existsAndEqual(EntityType.FIELD_TYPE, newFieldType.getName().toString(), null); 46 46 return oldFieldType; 47 47 } … … 85 85 if (updated) { 86 86 oldRecordType = typeManager.updateRecordType(oldRecordType); 87 importListener.updated(EntityType.RECORD_TYPE, oldRecordType.getId(), null);87 importListener.updated(EntityType.RECORD_TYPE, null, oldRecordType.getId(), oldRecordType.getVersion()); 88 88 } else { 89 importListener.existsAndEqual(EntityType.RECORD_TYPE, oldRecordType.getId());89 importListener.existsAndEqual(EntityType.RECORD_TYPE, null, oldRecordType.getId()); 90 90 } 91 91 return oldRecordType; 92 92 } else { 93 93 RecordType createdRecordType = typeManager.createRecordType(newRecordType); 94 importListener.created(EntityType.RECORD_TYPE, createdRecordType.getId(), null);94 importListener.created(EntityType.RECORD_TYPE, null, createdRecordType.getId()); 95 95 return createdRecordType; 96 } 97 } 98 99 public Record importRecord(Record newRecord) throws RepositoryException { 100 Record oldRecord = null; 101 if (newRecord.getId() != null) { 102 try { 103 oldRecord = repository.read(newRecord.getId()); 104 } catch (RecordNotFoundException e) { 105 // ok 106 } 107 } 108 109 if (oldRecord != null) { 110 if (newRecord.softEquals(oldRecord)) { 111 importListener.existsAndEqual(EntityType.RECORD, null, newRecord.getId().toString()); 112 return oldRecord; 113 } else { 114 // Delete fields which are not present in the new record anymore 115 for (Map.Entry<QName, Object> field : oldRecord.getFields().entrySet()) { 116 if (!newRecord.hasField(field.getKey())) { 117 newRecord.delete(field.getKey(), true); 118 } 119 } 120 Record updatedRecord = repository.update(newRecord); 121 importListener.updated(EntityType.RECORD, null, updatedRecord.getId().toString(), updatedRecord.getVersion()); 122 return updatedRecord; 123 } 124 } else { 125 Record createdRecord = repository.create(newRecord); 126 importListener.created(EntityType.RECORD, null, createdRecord.getId().toString()); 127 return createdRecord; 96 128 } 97 129 } -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/JsonImportTool.java
r4127 r4130 6 6 import org.codehaus.jackson.JsonToken; 7 7 import org.codehaus.jackson.map.MappingJsonFactory; 8 import org.joda.time.DateTime; 9 import org.joda.time.LocalDate; 8 10 import org.lilycms.client.Client; 9 11 import org.lilycms.repository.api.*; … … 61 63 namespaces.clear(); 62 64 63 JsonFactory f = new MappingJsonFactory(); 64 JsonParser jp = f.createJsonParser(is); 65 JsonFactory jsonFactory = new MappingJsonFactory(); 66 jsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS, true); 67 jsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); 68 JsonParser jp = jsonFactory.createJsonParser(is); 65 69 66 70 JsonToken current; … … 166 170 Record record = repository.newRecord(); 167 171 172 String id = getString(node, "id", null); 173 if (id != null) { 174 record.setId(repository.getIdGenerator().newRecordId(id)); 175 } 176 168 177 String type = getString(node, "type"); 169 178 record.setRecordType(type); … … 174 183 if (name.contains(":")) { 175 184 QName qname = parseQName(name); 176 String value = getString(node, name); 185 ValueType valueType = typeManager.getFieldTypeByName(qname).getValueType(); 186 Object value = readMultiValue(getNode(node, name), valueType, name); 177 187 record.setField(qname, value); 178 188 } 179 189 } 180 190 181 record = repository.create(record); 182 System.out.println("Created record " + record.getId()); 191 importTool.importRecord(record); 192 } 193 194 private Object readMultiValue(JsonNode node, ValueType valueType, String prop) throws ImportException { 195 if (valueType.isMultiValue()) { 196 if (!node.isArray()) { 197 throw new ImportException("Multi-value value should be specified as array in " + prop); 198 } 199 200 List<Object> value = new ArrayList<Object>(); 201 for (int i = 0; i < node.size(); i++) { 202 value.add(readHierarchical(node.get(i), valueType, prop)); 203 } 204 205 return value; 206 } else { 207 return readHierarchical(node, valueType, prop); 208 } 209 } 210 211 private Object readHierarchical(JsonNode node, ValueType valueType, String prop) throws ImportException { 212 if (valueType.isHierarchical()) { 213 if (!node.isArray()) { 214 throw new ImportException("Hierarchical value should be specified as an array in " + prop); 215 } 216 217 Object[] elements = new Object[node.size()]; 218 for (int i = 0; i < node.size(); i++) { 219 elements[i] = readPrimitive(node.get(i), valueType, prop); 220 } 221 222 return new HierarchyPath(elements); 223 } else { 224 return readPrimitive(node, valueType, prop); 225 } 226 } 227 228 private Object readPrimitive(JsonNode node, ValueType valueType, String prop) throws ImportException { 229 String primitive = valueType.getPrimitive().getName(); 230 231 if (primitive.equals("STRING")) { 232 if (!node.isTextual()) 233 throw new ImportException("Expected text value for " + prop); 234 235 return node.getTextValue(); 236 } else if (primitive.equals("INTEGER")) { 237 if (!node.isIntegralNumber()) 238 throw new ImportException("Expected int value for " + prop); 239 240 return node.getIntValue(); 241 } else if (primitive.equals("LONG")) { 242 if (!node.isIntegralNumber()) 243 throw new ImportException("Expected long value for " + prop); 244 245 return node.getLongValue(); 246 } else if (primitive.equals("BOOLEAN")) { 247 if (!node.isBoolean()) 248 throw new ImportException("Expected boolean value for " + prop); 249 250 return node.getBooleanValue(); 251 } else if (primitive.equals("LINK")) { 252 if (!node.isTextual()) 253 throw new ImportException("Expected text value for " + prop); 254 255 return Link.fromString(node.getTextValue(), repository.getIdGenerator()); 256 } else if (primitive.equals("DATE")) { 257 if (!node.isTextual()) 258 throw new ImportException("Expected text value for " + prop); 259 260 return new LocalDate(node.getTextValue()); 261 } else if (primitive.equals("DATETIME")) { 262 if (!node.isTextual()) 263 throw new ImportException("Expected text value for " + prop); 264 265 return new DateTime(node.getTextValue()); 266 } else { 267 throw new ImportException("Primitive value type not supported by import tool: " + primitive); 268 } 183 269 } 184 270
Note: See TracChangeset
for help on using the changeset viewer.