001package org.apache.archiva.redback.rest.api.model;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import javax.xml.bind.annotation.XmlRootElement;
022import java.io.Serializable;
023
024/**
025 * @author Olivier Lamy
026 * @since 1.4
027 */
028@XmlRootElement( name = "permission" )
029public class Permission
030    implements Serializable
031{
032    private String name;
033
034    private String description;
035
036    private Operation operation;
037
038    private Resource resource;
039
040    private boolean permanent;
041
042    public Permission()
043    {
044        // no op
045    }
046
047    public Permission( org.apache.archiva.redback.rbac.Permission permission )
048    {
049        this.name = permission.getName();
050        this.description = permission.getDescription();
051        this.operation = permission.getOperation() == null ? null : new Operation( permission.getOperation() );
052        this.resource = permission.getResource() == null ? null : new Resource( permission.getResource() );
053        this.permanent = permission.isPermanent();
054    }
055
056    public String getName()
057    {
058        return name;
059    }
060
061    public void setName( String name )
062    {
063        this.name = name;
064    }
065
066    public Operation getOperation()
067    {
068        return operation;
069    }
070
071    public void setOperation( Operation operation )
072    {
073        this.operation = operation;
074    }
075
076    public Resource getResource()
077    {
078        return resource;
079    }
080
081    public void setResource( Resource resource )
082    {
083        this.resource = resource;
084    }
085
086    @Override
087    public String toString()
088    {
089        final StringBuilder sb = new StringBuilder();
090        sb.append( "Permission" );
091        sb.append( "{name='" ).append( name ).append( '\'' );
092        sb.append( ", description='" ).append( description ).append( '\'' );
093        sb.append( ", operation=" ).append( operation );
094        sb.append( ", resource=" ).append( resource );
095        sb.append( ", permanent=" ).append( permanent );
096        sb.append( '}' );
097        return sb.toString();
098    }
099}