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.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    private static final long serialVersionUID = -5697869523880291618L;
034
035    protected String repositoryId;
036
037    protected String eventId;
038
039    protected Long eventDate;
040
041    protected String docUuid;
042
043    protected FileSystemItem fileSystemItem;
044
045    protected String fileSystemItemId;
046
047    protected String fileSystemItemName;
048
049    public FileSystemItemChangeImpl() {
050        // Needed for JSON deserialization
051    }
052
053    public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid,
054            String fileSystemItemId, String fileSystemItemName) {
055        this.eventId = eventId;
056        this.eventDate = eventDate;
057
058        // To be deprecated once the client uses the new filesystem API
059        this.repositoryId = repositoryId;
060        this.docUuid = docUuid;
061
062        // We store the fileSystemItemId for events that no longer have access
063        // to the full filesystem item description as is the case when a
064        // document is deleted
065        this.fileSystemItemId = fileSystemItemId;
066
067        // Just there to make debugging easier and tests more readable: the
068        // client should only need the fileSystemItemId.
069        this.fileSystemItemName = fileSystemItemName;
070    }
071
072    public FileSystemItemChangeImpl(String eventId, long eventDate, String repositoryId, String docUuid,
073            FileSystemItem fsItem) {
074        this(eventId, eventDate, repositoryId, docUuid, fsItem.getId(), fsItem.getName());
075        fileSystemItem = fsItem;
076    }
077
078    @Override
079    public String getFileSystemItemId() {
080        return fileSystemItemId;
081    }
082
083    @Override
084    public void setFileSystemItemId(String fileSystemItemId) {
085        this.fileSystemItemId = fileSystemItemId;
086    }
087
088    @Override
089    public String getFileSystemItemName() {
090        return fileSystemItemName;
091    }
092
093    @Override
094    public void setFileSystemItemName(String fileSystemItemName) {
095        this.fileSystemItemName = fileSystemItemName;
096    }
097
098    @Override
099    public String getRepositoryId() {
100        return repositoryId;
101    }
102
103    @Override
104    public void setRepositoryId(String repositoryId) {
105        this.repositoryId = repositoryId;
106    }
107
108    @Override
109    public String getEventId() {
110        return eventId;
111    }
112
113    @Override
114    public void setEventId(String eventId) {
115        this.eventId = eventId;
116    }
117
118    @Override
119    public Long getEventDate() {
120        return eventDate;
121    }
122
123    @Override
124    public void setEventDate(Long eventDate) {
125        this.eventDate = eventDate;
126    }
127
128    @Override
129    public String getDocUuid() {
130        return docUuid;
131    }
132
133    @Override
134    public void setDocUuid(String docUuid) {
135        this.docUuid = docUuid;
136    }
137
138    @Override
139    public FileSystemItem getFileSystemItem() {
140        return fileSystemItem;
141    }
142
143    @Override
144    @JsonDeserialize(using = FileSystemItemDeserializer.class)
145    public void setFileSystemItem(FileSystemItem fileSystemItem) {
146        this.fileSystemItem = fileSystemItem;
147    }
148
149    @Override
150    public String toString() {
151        return String.format(
152                "%s(eventId=\"%s\", eventDate=%d, repositoryId=%s, docUuid=%s, fileSystemItemId=%s, fileSystemItemName=%s, fileSystemItem=%s)",
153                getClass().getSimpleName(), eventId, eventDate, repositoryId, docUuid, fileSystemItemId,
154                fileSystemItemName, fileSystemItem);
155
156    }
157
158}