/** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.airavata.sharing.registry.db.repositories; import org.apache.airavata.sharing.registry.db.entities.SharingEntity; import org.apache.airavata.sharing.registry.db.entities.UserEntity; import org.apache.airavata.sharing.registry.db.entities.UserPK; import org.apache.airavata.sharing.registry.db.utils.DBConstants; import org.apache.airavata.sharing.registry.models.SharingRegistryException; import org.apache.airavata.sharing.registry.models.User; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; public class UserRepository extends AbstractRepository<User, UserEntity, UserPK> { private final static Logger logger = LoggerFactory.getLogger(UserRepository.class); public UserRepository() { super(User.class, UserEntity.class); } //TODO Replace with prepared statements public List<User> getAccessibleUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException { String query = "SELECT DISTINCT u from " + UserEntity.class.getSimpleName() + " u, " + SharingEntity.class.getSimpleName() + " s"; query += " WHERE "; query += "u." + DBConstants.UserTable.USER_ID + " = s." + DBConstants.SharingTable.GROUP_ID + " AND "; query += "u." + DBConstants.UserTable.DOMAIN_ID + " = s." + DBConstants.SharingTable.DOMAIN_ID + " AND "; query += "u." + DBConstants.UserTable.DOMAIN_ID + " = '" + domainId + "' AND "; query += "s." + DBConstants.SharingTable.ENTITY_ID + " = '" + entityId + "' AND "; query += "s." + DBConstants.SharingTable.PERMISSION_TYPE_ID + " = '" + permissionTypeId + "'"; if(permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))){ query += "AND s." + DBConstants.SharingTable.SHARING_TYPE + " LIKE 'DIRECT_%'"; } query += " ORDER BY s.createdTime DESC"; return select(query, 0, -1); } }