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 <[email protected]> 018 */ 019package org.nuxeo.drive.service.impl; 020 021import org.nuxeo.drive.adapter.FileSystemItem; 022import org.nuxeo.drive.service.FileSystemItemChange; 023 024import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 025 026/** 027 * Default implementation of a {@link FileSystemItemChange}. 028 * 029 * @author Antoine Taillefer 030 */ 031public class FileSystemItemChangeImpl implements FileSystemItemChange { 032 033 protected String repositoryId; 034 035 protected String eventId; 036 037 protected Long eventDate; 038 039 protected String docUuid; 040 041 protected FileSystemItem fileSystemItem; 042 043 protected String fileSystemItemId; 044 045 protected String fileSystemItemName; 046 047 public FileSystemItemChangeImpl() { 048 // Needed for JSON deserialization 049 } 050 051 public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid, 052 String fileSystemItemId, String fileSystemItemName) { 053 this.eventId = eventId; 054 this.eventDate = eventDate; 055 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 @JsonDeserialize(using = FileSystemItemDeserializer.class) 142 public void setFileSystemItem(FileSystemItem fileSystemItem) { 143 this.fileSystemItem = fileSystemItem; 144 } 145 146 @Override 147 public String toString() { 148 return String.format( 149 "%s(eventId=\"%s\", eventDate=%d, repositoryId=%s, docUuid=%s, fileSystemItemId=%s, fileSystemItemName=%s, fileSystemItem=%s)", 150 getClass().getSimpleName(), eventId, eventDate, repositoryId, docUuid, fileSystemItemId, 151 fileSystemItemName, fileSystemItem); 152 153 } 154 155}