001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.common.util.channel.model;
017
018import org.kuali.common.util.Assert;
019
020import com.google.common.base.Optional;
021
022public final class RemoteFile {
023
024        private final String absolutePath;
025        private final Optional<Integer> groupId;
026        private final Optional<Integer> userId;
027        private final Optional<Integer> permissions;
028        private final Optional<Long> size;
029        private final boolean directory;
030        private final Optional<Status> status;
031
032        public static class Builder {
033
034                // Required
035                private final String absolutePath;
036
037                // Optional
038                private Optional<Integer> groupId = Optional.absent();
039                private Optional<Integer> userId = Optional.absent();
040                private Optional<Integer> permissions = Optional.absent();
041                private Optional<Long> size = Optional.absent();
042                private boolean directory = false;
043                private Optional<Status> status = Optional.absent();
044
045                public Builder(String absolutePath) {
046                        this.absolutePath = absolutePath;
047                }
048
049                public Builder clone(RemoteFile other) {
050                        this.groupId = other.groupId;
051                        this.userId = other.userId;
052                        this.permissions = other.permissions;
053                        this.size = other.size;
054                        this.directory = other.directory;
055                        this.status = other.status;
056                        return this;
057                }
058
059                public Builder groupId(int groupId) {
060                        this.groupId = Optional.of(groupId);
061                        return this;
062                }
063
064                public Builder userId(int userId) {
065                        this.userId = Optional.of(userId);
066                        return this;
067                }
068
069                public Builder permissions(int permissions) {
070                        this.permissions = Optional.of(permissions);
071                        return this;
072                }
073
074                public Builder size(long size) {
075                        this.size = Optional.of(size);
076                        return this;
077                }
078
079                public Builder directory(boolean directory) {
080                        this.directory = directory;
081                        return this;
082                }
083
084                public Builder status(Status status) {
085                        this.status = Optional.of(status);
086                        return this;
087                }
088
089                public RemoteFile build() {
090                        Assert.noBlanks(absolutePath);
091                        Assert.noNulls(groupId, userId, permissions, size, directory, status);
092                        if (size.isPresent()) {
093                                Assert.notNegative(size.get());
094                        }
095                        return new RemoteFile(this);
096                }
097
098        }
099
100        private RemoteFile(Builder builder) {
101                this.absolutePath = builder.absolutePath;
102                this.groupId = builder.groupId;
103                this.userId = builder.userId;
104                this.permissions = builder.permissions;
105                this.size = builder.size;
106                this.directory = builder.directory;
107                this.status = builder.status;
108        }
109
110        public String getAbsolutePath() {
111                return absolutePath;
112        }
113
114        public Optional<Integer> getGroupId() {
115                return groupId;
116        }
117
118        public Optional<Integer> getUserId() {
119                return userId;
120        }
121
122        public Optional<Integer> getPermissions() {
123                return permissions;
124        }
125
126        public Optional<Long> getSize() {
127                return size;
128        }
129
130        public boolean isDirectory() {
131                return directory;
132        }
133
134        public Optional<Status> getStatus() {
135                return status;
136        }
137
138}