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.onedrive;
020
021import java.util.Objects;
022
023import org.nuxeo.ecm.liveconnect.core.AbstractLiveConnectFile;
024import org.nuxeo.ecm.liveconnect.core.LiveConnectFileInfo;
025import org.nuxeo.onedrive.client.OneDriveFile;
026
027/**
028 * @since 8.2
029 */
030public class OneDriveLiveConnectFile extends AbstractLiveConnectFile {
031
032    private static final long serialVersionUID = 1L;
033
034    private final String filename;
035
036    private final long fileSize;
037
038    private final String digest;
039
040    public OneDriveLiveConnectFile(LiveConnectFileInfo info, OneDriveFile.Metadata file) {
041        super(info);
042        this.filename = Objects.requireNonNull(file.getName());
043        this.fileSize = file.getSize();
044        this.digest = Objects.requireNonNull(getDigest(file));
045    }
046
047    @Override
048    public String getFilename() {
049        return filename;
050    }
051
052    @Override
053    public long getFileSize() {
054        return fileSize;
055    }
056
057    @Override
058    public String getDigest() {
059        return digest;
060    }
061
062    private static String getDigest(OneDriveFile.Metadata file) {
063        return file.getSha1Hash() == null ? file.getETag() : file.getSha1Hash();
064    }
065
066}