001/**
002 * Copyright 2005-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.rice.krad.dao.impl;
017
018import org.apache.commons.lang.StringUtils;
019import org.apache.ojb.broker.query.Criteria;
020import org.apache.ojb.broker.query.QueryFactory;
021import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
022import org.kuali.rice.krad.dao.MaintenanceDocumentDao;
023import org.kuali.rice.krad.maintenance.MaintenanceLock;
024import org.kuali.rice.krad.util.KRADPropertyConstants;
025
026/**
027 * This class is the OJB implementation of the MaintenanceDocumentDao interface.
028 */
029public class MaintenanceDocumentDaoOjb extends PlatformAwareDaoBaseOjb implements MaintenanceDocumentDao {
030
031//    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentDaoOjb.class);
032
033    /**
034     * @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String, java.lang.String)
035     */
036    public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
037
038        String lockingDocNumber = "";
039
040        // build the query criteria
041        Criteria criteria = new Criteria();
042        criteria.addEqualTo("lockingRepresentation", lockingRepresentation);
043
044        // if a docHeaderId is specified, then it will be excluded from the
045        // locking representation test.
046        if (StringUtils.isNotBlank(documentNumber)) {
047            criteria.addNotEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber);
048        }
049
050        // attempt to retrieve a document based off this criteria
051        MaintenanceLock maintenanceLock = (MaintenanceLock) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria));
052
053        // if a document was found, then there's already one out there pending, and
054        // we consider it 'locked' and we return the docnumber.
055        if (maintenanceLock != null) {
056            lockingDocNumber = maintenanceLock.getDocumentNumber();
057        }
058        return lockingDocNumber;
059    }
060
061}