001/**
002 * Copyright 2005-2016 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.rice.kim.impl.group;
017
018import java.sql.Timestamp;
019import javax.persistence.Column;
020import javax.persistence.Entity;
021import javax.persistence.GeneratedValue;
022import javax.persistence.Id;
023import javax.persistence.Table;
024import org.kuali.rice.kim.api.group.GroupMember;
025import org.kuali.rice.kim.api.group.GroupMemberContract;
026import org.kuali.rice.kim.impl.membership.AbstractMemberBo;
027import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
028import javax.persistence.Cacheable;
029
030@Entity
031@Cacheable(false)
032@Table(name = "KRIM_GRP_MBR_T")
033public class GroupMemberBo extends AbstractMemberBo implements GroupMemberContract {
034
035    private static final long serialVersionUID = 6773749266062306217L;
036
037    @PortableSequenceGenerator(name = "KRIM_GRP_MBR_ID_S")
038    @GeneratedValue(generator = "KRIM_GRP_MBR_ID_S")
039    @Id
040    @Column(name = "GRP_MBR_ID")
041    private String id;
042
043    @Column(name = "GRP_ID")
044    private String groupId;
045
046    public static GroupMember to(GroupMemberBo bo) {
047        if (bo == null) {
048            return null;
049        }
050        return GroupMember.Builder.create(bo).build();
051    }
052
053    public static GroupMemberBo from(GroupMember im) {
054        if (im == null) {
055            return null;
056        }
057        GroupMemberBo bo = new GroupMemberBo();
058        bo.setId(im.getId());
059        bo.setGroupId(im.getGroupId());
060        bo.setMemberId(im.getMemberId());
061        bo.setTypeCode(im.getType().getCode());
062        bo.setActiveFromDateValue(im.getActiveFromDate() == null ? null : new Timestamp(im.getActiveFromDate().getMillis()));
063        bo.setActiveToDateValue(im.getActiveToDate() == null ? null : new Timestamp(im.getActiveToDate().getMillis()));
064        bo.setVersionNumber(im.getVersionNumber());
065        bo.setObjectId(im.getObjectId());
066        return bo;
067    }
068
069    @Override
070    public String getId() {
071        return id;
072    }
073
074    public void setId(String id) {
075        this.id = id;
076    }
077
078    @Override
079    public String getGroupId() {
080        return groupId;
081    }
082
083    public void setGroupId(String groupId) {
084        this.groupId = groupId;
085    }
086}