001/*
002 * (C) Copyright 2015-2016 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 *     Kevin Leturc
018 */
019package org.nuxeo.ecm.liveconnect.core;
020
021import java.io.Serializable;
022import java.util.Objects;
023import java.util.Optional;
024
025import com.google.common.base.MoreObjects;
026import com.google.common.base.MoreObjects.ToStringHelper;
027
028/**
029 * @since 8.1
030 */
031public class LiveConnectFileInfo implements Serializable {
032
033    private static final long serialVersionUID = 1L;
034
035    private final String user;
036
037    private final String fileId;
038
039    private final String revisionId;
040
041    public LiveConnectFileInfo(String user, String fileId) {
042        this(user, fileId, null);
043    }
044
045    public LiveConnectFileInfo(String user, String fileId, String revisionId) {
046        this.user = Objects.requireNonNull(user);
047        this.fileId = Objects.requireNonNull(fileId);
048        this.revisionId = revisionId;
049    }
050
051    public String getUser() {
052        return user;
053    }
054
055    public String getFileId() {
056        return fileId;
057    }
058
059    public Optional<String> getRevisionId() {
060        return Optional.ofNullable(revisionId);
061    }
062
063    @Override
064    public String toString() {
065        ToStringHelper helper = MoreObjects.toStringHelper(this);
066        helper.add("user", user);
067        helper.add("fileId", fileId);
068        getRevisionId().ifPresent(rev -> helper.add("revisionId", rev));
069        return helper.toString();
070    }
071}