001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Antoine Taillefer <ataillefer@nuxeo.com> 016 */ 017package org.nuxeo.drive.service.impl; 018 019import org.codehaus.jackson.annotate.JsonIgnore; 020import org.nuxeo.drive.adapter.FileSystemItem; 021import org.nuxeo.drive.service.FileSystemItemChange; 022 023/** 024 * Default implementation of a {@link FileSystemItemChange}. 025 * 026 * @author Antoine Taillefer 027 */ 028public class FileSystemItemChangeImpl implements FileSystemItemChange { 029 030 private static final long serialVersionUID = -5697869523880291618L; 031 032 protected String repositoryId; 033 034 protected String eventId; 035 036 protected Long eventDate; 037 038 protected String docUuid; 039 040 protected FileSystemItem fileSystemItem; 041 042 protected String fileSystemItemId; 043 044 protected String fileSystemItemName; 045 046 public FileSystemItemChangeImpl() { 047 // Needed for JSON deserialization 048 } 049 050 public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid, 051 String fileSystemItemId, String fileSystemItemName) { 052 this.eventId = eventId; 053 this.eventDate = eventDate; 054 055 // To be deprecated once the client uses the new filesystem API 056 this.repositoryId = repositoryId; 057 this.docUuid = docUuid; 058 059 // We store the fileSystemItemId for events that no longer have access 060 // to the full filesystem item description as is the case when a 061 // document is deleted 062 this.fileSystemItemId = fileSystemItemId; 063 064 // Just there to make debugging easier and tests more readable: the 065 // client should only need the fileSystemItemId. 066 this.fileSystemItemName = fileSystemItemName; 067 } 068 069 public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid, 070 FileSystemItem fsItem) { 071 this(eventId, eventDate, repositoryId, docUuid, fsItem.getId(), fsItem.getName()); 072 fileSystemItem = fsItem; 073 } 074 075 @Override 076 public String getFileSystemItemId() { 077 return fileSystemItemId; 078 } 079 080 @Override 081 public void setFileSystemItemId(String fileSystemItemId) { 082 this.fileSystemItemId = fileSystemItemId; 083 } 084 085 @Override 086 public String getFileSystemItemName() { 087 return fileSystemItemName; 088 } 089 090 @Override 091 public void setFileSystemItemName(String fileSystemItemName) { 092 this.fileSystemItemName = fileSystemItemName; 093 } 094 095 @Override 096 public String getRepositoryId() { 097 return repositoryId; 098 } 099 100 @Override 101 public void setRepositoryId(String repositoryId) { 102 this.repositoryId = repositoryId; 103 } 104 105 @Override 106 public String getEventId() { 107 return eventId; 108 } 109 110 @Override 111 public void setEventId(String eventId) { 112 this.eventId = eventId; 113 } 114 115 @Override 116 public Long getEventDate() { 117 return eventDate; 118 } 119 120 @Override 121 public void setEventDate(Long eventDate) { 122 this.eventDate = eventDate; 123 } 124 125 @Override 126 public String getDocUuid() { 127 return docUuid; 128 } 129 130 @Override 131 public void setDocUuid(String docUuid) { 132 this.docUuid = docUuid; 133 } 134 135 @Override 136 public FileSystemItem getFileSystemItem() { 137 return fileSystemItem; 138 } 139 140 @Override 141 @JsonIgnore 142 public void setFileSystemItem(FileSystemItem fileSystemItem) { 143 this.fileSystemItem = fileSystemItem; 144 } 145 146 @Override 147 public String toString() { 148 if (fileSystemItem != null) { 149 return String.format("%s(eventId=\"%s\", eventDate=%d, item=%s)", getClass().getSimpleName(), eventId, 150 eventDate, fileSystemItem); 151 } else { 152 return String.format("%s(eventId=\"%s\", eventDate=%d)", getClass().getSimpleName(), eventId, eventDate); 153 } 154 } 155 156}