protected List<ContentTypeImpl> mergeWithStoredContentTypes( final Collection<WritableContentType> types) throws IllegalArgumentException { final List<ContentTypeImpl> resultingTypes = new ArrayList<ContentTypeImpl>(types.size()); final Collection<? extends ContentType> storedContentTypes; final ContentTypeId[] ids = new ContentTypeId[types.size()]; int i = 0; for (ContentType type : types) { ids[i++] = type.getContentTypeID(); } storedContentTypes = SmartContentSPI.getInstance() .getContentTypeReader() .readContentTypeFromPersistentStorage(ids); for (ContentType type : storedContentTypes) { final ContentTypeImpl contentTypeImpl = getContentTypeImpl(type); contentTypeImpl.setFromPersistentStorage(true); resultingTypes.add(contentTypeImpl); } if (logger.isDebugEnabled()) { logger.debug( new StringBuilder("After getting from persistent storage size is of 2b ReturnedList is ") .append(resultingTypes.size()) .toString()); } for (MutableContentType type : types) { if (logger.isDebugEnabled()) { logger.debug(new StringBuilder("Type ID is ").append(type.getContentTypeID()).toString()); } int index = resultingTypes.indexOf(type); if (index >= 0) { logger.debug("Just merging"); final ContentTypeImpl get = resultingTypes.get(index); merge(get, type); get.setFromPersistentStorage(true); } else { logger.debug("Adding to list"); resultingTypes.add(getContentTypeImpl(type)); } } return resultingTypes; }
protected void merge(ContentTypeImpl typeImpl, ContentType contentType) throws IllegalArgumentException { typeImpl.setContentTypeID(contentType.getContentTypeID()); typeImpl.setCreationDate(contentType.getCreationDate()); typeImpl.setPrimaryFieldName(contentType.getPrimaryFieldName()); typeImpl.setDisplayName(contentType.getDisplayName()); typeImpl.setFromPersistentStorage( contentType instanceof PersistableContentType ? ((PersistableContentType) contentType).isFromPersistentStorage() : false); typeImpl.setLastModifiedDate(contentType.getLastModifiedDate()); typeImpl.setEntityTagValue(contentType.getEntityTagValue()); typeImpl.setParent(contentType.getParent()); typeImpl.getMutableFieldDefs().clear(); typeImpl.getMutableFieldDefs().addAll(contentType.getOwnFieldDefs().values()); typeImpl.getMutableRepresentationDefs().clear(); typeImpl.getMutableRepresentationDefs().addAll(contentType.getRepresentationDefs().values()); typeImpl.getMutableStatuses().clear(); typeImpl.getMutableStatuses().addAll(contentType.getStatuses().values()); typeImpl.setRepresentations(contentType.getRepresentations()); }