001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Antoine Taillefer <ataillefer@nuxeo.com> 018 */ 019package org.nuxeo.drive.service.impl; 020 021import org.codehaus.jackson.annotate.JsonIgnore; 022import org.nuxeo.drive.adapter.FileSystemItem; 023import org.nuxeo.drive.service.FileSystemItemChange; 024 025/** 026 * Default implementation of a {@link FileSystemItemChange}. 027 * 028 * @author Antoine Taillefer 029 */ 030public class FileSystemItemChangeImpl implements FileSystemItemChange { 031 032 private static final long serialVersionUID = -5697869523880291618L; 033 034 protected String repositoryId; 035 036 protected String eventId; 037 038 protected Long eventDate; 039 040 protected String docUuid; 041 042 protected FileSystemItem fileSystemItem; 043 044 protected String fileSystemItemId; 045 046 protected String fileSystemItemName; 047 048 public FileSystemItemChangeImpl() { 049 // Needed for JSON deserialization 050 } 051 052 public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid, 053 String fileSystemItemId, String fileSystemItemName) { 054 this.eventId = eventId; 055 this.eventDate = eventDate; 056 057 // To be deprecated once the client uses the new filesystem API 058 this.repositoryId = repositoryId; 059 this.docUuid = docUuid; 060 061 // We store the fileSystemItemId for events that no longer have access 062 // to the full filesystem item description as is the case when a 063 // document is deleted 064 this.fileSystemItemId = fileSystemItemId; 065 066 // Just there to make debugging easier and tests more readable: the 067 // client should only need the fileSystemItemId. 068 this.fileSystemItemName = fileSystemItemName; 069 } 070 071 public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid, 072 FileSystemItem fsItem) { 073 this(eventId, eventDate, repositoryId, docUuid, fsItem.getId(), fsItem.getName()); 074 fileSystemItem = fsItem; 075 } 076 077 @Override 078 public String getFileSystemItemId() { 079 return fileSystemItemId; 080 } 081 082 @Override 083 public void setFileSystemItemId(String fileSystemItemId) { 084 this.fileSystemItemId = fileSystemItemId; 085 } 086 087 @Override 088 public String getFileSystemItemName() { 089 return fileSystemItemName; 090 } 091 092 @Override 093 public void setFileSystemItemName(String fileSystemItemName) { 094 this.fileSystemItemName = fileSystemItemName; 095 } 096 097 @Override 098 public String getRepositoryId() { 099 return repositoryId; 100 } 101 102 @Override 103 public void setRepositoryId(String repositoryId) { 104 this.repositoryId = repositoryId; 105 } 106 107 @Override 108 public String getEventId() { 109 return eventId; 110 } 111 112 @Override 113 public void setEventId(String eventId) { 114 this.eventId = eventId; 115 } 116 117 @Override 118 public Long getEventDate() { 119 return eventDate; 120 } 121 122 @Override 123 public void setEventDate(Long eventDate) { 124 this.eventDate = eventDate; 125 } 126 127 @Override 128 public String getDocUuid() { 129 return docUuid; 130 } 131 132 @Override 133 public void setDocUuid(String docUuid) { 134 this.docUuid = docUuid; 135 } 136 137 @Override 138 public FileSystemItem getFileSystemItem() { 139 return fileSystemItem; 140 } 141 142 @Override 143 @JsonIgnore 144 public void setFileSystemItem(FileSystemItem fileSystemItem) { 145 this.fileSystemItem = fileSystemItem; 146 } 147 148 @Override 149 public String toString() { 150 return String.format( 151 "%s(eventId=\"%s\", eventDate=%d, repositoryId=%s, docUuid=%s, fileSystemItemId=%s, fileSystemItemName=%s, fileSystemItem=%s)", 152 getClass().getSimpleName(), eventId, eventDate, repositoryId, docUuid, fileSystemItemId, 153 fileSystemItemName, fileSystemItem); 154 155 } 156 157}