changing package name due to class loading problem
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/e0f63bcb Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/e0f63bcb Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/e0f63bcb Branch: refs/heads/develop Commit: e0f63bcb936e496d0630de19637673b0a5a31862 Parents: 9085dfe Author: Anuj Bhandar <[email protected]> Authored: Mon Feb 6 17:02:57 2017 -0500 Committer: Anuj Bhandar <[email protected]> Committed: Tue Feb 28 12:55:35 2017 -0500 ---------------------------------------------------------------------- .../org/apache/airavata/server/ServerMain.java | 6 +- .../core/UserProfileRegistryException.java | 28 --- .../core/entities/NSFDemographicsEntity.java | 94 ------- .../core/entities/UserProfileEntity.java | 247 ------------------- .../core/repositories/AbstractRepository.java | 98 -------- .../repositories/UserProfileRepository.java | 87 ------- .../airavata/registry/core/utils/Committer.java | 27 -- .../registry/core/utils/JPAConstants.java | 32 --- .../airavata/registry/core/utils/JPAUtils.java | 83 ------- .../core/utils/ObjectMapperSingleton.java | 39 --- .../registry/core/utils/QueryConstants.java | 22 -- .../airavata/registry/core/utils/Utils.java | 156 ------------ .../core/UserProfileRegistryException.java | 28 +++ .../core/entities/NSFDemographicsEntity.java | 94 +++++++ .../core/entities/UserProfileEntity.java | 247 +++++++++++++++++++ .../core/repositories/AbstractRepository.java | 98 ++++++++ .../repositories/UserProfileRepository.java | 87 +++++++ .../user/registry/core/utils/Committer.java | 27 ++ .../user/registry/core/utils/JPAConstants.java | 32 +++ .../user/registry/core/utils/JPAUtils.java | 83 +++++++ .../core/utils/ObjectMapperSingleton.java | 39 +++ .../registry/core/utils/QueryConstants.java | 22 ++ .../user/registry/core/utils/Utils.java | 155 ++++++++++++ .../src/main/resources/META-INF/persistence.xml | 4 +- .../user-profile/user-profile-service/pom.xml | 5 + .../server/UserProfileServiceHandler.java | 4 +- 26 files changed, 924 insertions(+), 920 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java ---------------------------------------------------------------------- diff --git a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java index 4fe2651..760d9a0 100644 --- a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java +++ b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java @@ -60,7 +60,7 @@ public class ServerMain { private static final String API_SERVER = "apiserver"; private static final String CREDENTIAL_STORE = "credentialstore"; private static final String REGISTRY_SERVER = "regserver"; - private static final String SHARING_SERVER = "sharing_server"; + //private static final String SHARING_SERVER = "sharing_server"; private static final String GFAC_SERVER = "gfac"; private static final String ORCHESTRATOR = "orchestrator"; private static final String USER_PROFILE = "user_profile"; @@ -115,7 +115,7 @@ public class ServerMain { serverList.clear(); serverList.add(REGISTRY_SERVER); // registry server should start before everything serverList.add(CREDENTIAL_STORE); // credential store should start before api server - serverList.add(SHARING_SERVER); + //serverList.add(SHARING_SERVER); serverList.add(API_SERVER); serverList.add(ORCHESTRATOR); serverList.add(GFAC_SERVER); @@ -124,7 +124,7 @@ public class ServerMain { serverList.clear(); serverList.add(REGISTRY_SERVER); // registry server should start before everything serverList.add(CREDENTIAL_STORE); // credential store should start before api server - serverList.add(SHARING_SERVER); + //serverList.add(SHARING_SERVER); serverList.add(API_SERVER); serverList.add(ORCHESTRATOR); } else if (serverList.indexOf(EXECUTION) > -1) { http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/UserProfileRegistryException.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/UserProfileRegistryException.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/UserProfileRegistryException.java deleted file mode 100644 index 3bf5044..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/UserProfileRegistryException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * 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.registry.core; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UserProfileRegistryException extends Exception { - private final static Logger logger = LoggerFactory.getLogger(UserProfileRegistryException.class); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/NSFDemographicsEntity.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/NSFDemographicsEntity.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/NSFDemographicsEntity.java deleted file mode 100644 index fa0c7b2..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/NSFDemographicsEntity.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * 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.registry.core.entities; - -import javax.persistence.*; -import java.util.List; - -@Entity -@Table(name = "NSF_DEMOGRAPHIC") -public class NSFDemographicsEntity { - private String airavataInternalUserId; - private String gender; - private List<String> ethnicities; - private List<String> races; - private List<String> disabilities; - private UserProfileEntity userProfile; - - @Id - @Column(name = "AIRAVATA_INTERNAL_USER_ID") - public String getAiravataInternalUserId() { - return airavataInternalUserId; - } - - public void setAiravataInternalUserId(String userId) { - this.airavataInternalUserId = userId; - } - - @Column(name = "GENDER") - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } - - @ElementCollection - @CollectionTable(name="NSF_DEMOGRAPHIC_ETHNICITY", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getEthnicities() { - return ethnicities; - } - - public void setEthnicities(List<String> ethnicities) { - this.ethnicities = ethnicities; - } - - @ElementCollection - @CollectionTable(name="NSF_DEMOGRAPHIC_RACE", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getRaces() { - return races; - } - - public void setRaces(List<String> races) { - this.races = races; - } - - @ElementCollection - @CollectionTable(name="NSF_DEMOGRAPHIC_DISABILITY", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getDisabilities() { - return disabilities; - } - - public void setDisabilities(List<String> disabilities) { - this.disabilities = disabilities; - } - - @OneToOne(targetEntity = UserProfileEntity.class, cascade = CascadeType.ALL) - @PrimaryKeyJoinColumn(name = "AIRAVATA_INTERNAL_USER_ID", referencedColumnName = "AIRAVATA_INTERNAL_USER_ID") - public UserProfileEntity getUserProfile() { - return userProfile; - } - - public void setUserProfile(UserProfileEntity userProfile) { - this.userProfile = userProfile; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/UserProfileEntity.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/UserProfileEntity.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/UserProfileEntity.java deleted file mode 100644 index cf0429a..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/entities/UserProfileEntity.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * - * 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.registry.core.entities; - -import javax.persistence.*; -import java.util.List; - -@Entity -@Table(name="USER_PROFILE") -public class UserProfileEntity { - private String airavataInternalUserId; - private String userId; - private String gatewayId; - private String userModelVersion; - private String userName; - private String orcidId; - private String country; - private String homeOrganization; - private String orginationAffiliation; - private long creationTime; - private long lastAccessTime; - private long validUntil; - private String state; - private String comments; - private List<String> labeledURI; - private String gpgKey; - private String timeZone; - - private List<String> nationality; - private List<String> emails; - private List<String> phones; - private NSFDemographicsEntity nsfDemographics; - - @Id - @Column(name = "AIRAVATA_INTERNAL_USER_ID") - public String getAiravataInternalUserId() { - return airavataInternalUserId; - } - - public void setAiravataInternalUserId(String id) { - this.airavataInternalUserId = id; - } - - @Column(name = "USER_ID") - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - @Column(name = "GATEWAY_ID") - public String getGatewayId() { - return gatewayId; - } - - public void setGatewayId(String gatewayId) { - this.gatewayId = gatewayId; - } - - @Column(name = "USER_MODEL_VERSION") - public String getUserModelVersion() { - return userModelVersion; - } - - public void setUserModelVersion(String userModelVersion) { - this.userModelVersion = userModelVersion; - } - - @ElementCollection - @CollectionTable(name="USER_PROFILE_EMAIL", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getEmails() { - return emails; - } - - public void setEmails(List<String> emails) { - this.emails = emails; - } - - @Column(name = "USER_NAME") - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - @Column(name = "ORCID_ID") - public String getOrcidId() { - return orcidId; - } - - public void setOrcidId(String orcidId) { - this.orcidId = orcidId; - } - - @ElementCollection - @CollectionTable(name="USER_PROFILE_PHONE", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getPhones() { - return phones; - } - - public void setPhones(List<String> phones) { - this.phones = phones; - } - - @Column(name = "COUNTRY") - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - @ElementCollection - @CollectionTable(name="USER_PROFILE_NATIONALITY", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getNationality() { - return nationality; - } - - public void setNationality(List<String> nationality) { - this.nationality = nationality; - } - - @Column(name = "HOME_ORGANIZATION") - public String getHomeOrganization() { - return homeOrganization; - } - - public void setHomeOrganization(String homeOrganization) { - this.homeOrganization = homeOrganization; - } - - @Column(name = "ORIGINATION_AFFILIATION") - public String getOrginationAffiliation() { - return orginationAffiliation; - } - - public void setOrginationAffiliation(String orginationAffiliation) { - this.orginationAffiliation = orginationAffiliation; - } - - @Column(name="CREATION_TIME") - public long getCreationTime() { - return creationTime; - } - - public void setCreationTime(long creationTime) { - this.creationTime = creationTime; - } - - @Column(name = "LAST_ACCESS_TIME") - public long getLastAccessTime() { - return lastAccessTime; - } - - public void setLastAccessTime(long lastAccessTime) { - this.lastAccessTime = lastAccessTime; - } - - @Column(name = "VALID_UNTIL") - public long getValidUntil() { - return validUntil; - } - - public void setValidUntil(long validUntil) { - this.validUntil = validUntil; - } - - @Column(name = "STATE") - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - @Lob - @Column(name = "COMMENTS") - public String getComments() { - return comments; - } - - public void setComments(String comments) { - this.comments = comments; - } - - @ElementCollection - @CollectionTable(name="USER_PROFILE_LABELED_URI", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) - public List<String> getLabeledURI() { - return labeledURI; - } - - public void setLabeledURI(List<String> labeledURI) { - this.labeledURI = labeledURI; - } - - @Lob - @Column(name = "GPG_KEY") - public String getGpgKey() { - return gpgKey; - } - - public void setGpgKey(String gpgKey) { - this.gpgKey = gpgKey; - } - - @Column(name = "TIME_ZONE") - public String getTimeZone() { - return timeZone; - } - - public void setTimeZone(String timeZone) { - this.timeZone = timeZone; - } - - @OneToOne(targetEntity = NSFDemographicsEntity.class, cascade = CascadeType.ALL, mappedBy = "userProfile") - public NSFDemographicsEntity getNsfDemographics() { - return nsfDemographics; - } - - public void setNsfDemographics(NSFDemographicsEntity nsfDemographics) { - this.nsfDemographics = nsfDemographics; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java deleted file mode 100644 index a83928d..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/AbstractRepository.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * 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.registry.core.repositories; - -import org.apache.airavata.registry.core.utils.JPAUtils; -import org.apache.airavata.registry.core.utils.ObjectMapperSingleton; -import org.dozer.Mapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.Query; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public abstract class AbstractRepository<T, E, Id> { - private final static Logger logger = LoggerFactory.getLogger(AbstractRepository.class); - - private Class<T> thriftGenericClass; - private Class<E> dbEntityGenericClass; - - public AbstractRepository(Class<T> thriftGenericClass, Class<E> dbEntityGenericClass) { - this.thriftGenericClass = thriftGenericClass; - this.dbEntityGenericClass = dbEntityGenericClass; - } - - public T create(T t) { - return update(t); - } - - public T update(T t) { - Mapper mapper = ObjectMapperSingleton.getInstance(); - E entity = mapper.map(t, dbEntityGenericClass); - E persistedCopy = JPAUtils.execute(entityManager -> entityManager.merge(entity)); - return mapper.map(persistedCopy, thriftGenericClass); - } - - public boolean delete(Id id) { - JPAUtils.execute(entityManager -> { - E entity = entityManager.find(dbEntityGenericClass, id); - entityManager.remove(entity); - return entity; - }); - return true; - } - - public T get(Id id) { - E entity = JPAUtils.execute(entityManager -> entityManager - .find(dbEntityGenericClass, id)); - Mapper mapper = ObjectMapperSingleton.getInstance(); - return mapper.map(entity, thriftGenericClass); - } - - public List<T> select(String query, int limit, int offset) { - List resultSet = (List) JPAUtils.execute(entityManager -> entityManager.createQuery(query).setFirstResult(offset) - .setMaxResults(offset).getResultList()); - Mapper mapper = ObjectMapperSingleton.getInstance(); - List<T> gatewayList = new ArrayList<>(); - resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass))); - return gatewayList; - } - - public List<T> select(String query, int limit, int offset, Map<String, Object> queryParams) { - List resultSet = (List) JPAUtils.execute(entityManager -> { - Query jpaQuery = entityManager.createQuery(query); - - for (Map.Entry<String, Object> entry : queryParams.entrySet()) { - - jpaQuery.setParameter(entry.getKey(), entry.getValue()); - } - - return jpaQuery.setFirstResult(offset).setMaxResults(limit).getResultList(); - - }); - Mapper mapper = ObjectMapperSingleton.getInstance(); - List<T> gatewayList = new ArrayList<>(); - resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass))); - return gatewayList; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/UserProfileRepository.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/UserProfileRepository.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/UserProfileRepository.java deleted file mode 100644 index 0f9abad..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/repositories/UserProfileRepository.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * 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.registry.core.repositories; - -import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.registry.core.entities.UserProfileEntity; -import org.apache.airavata.registry.core.utils.QueryConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class UserProfileRepository extends AbstractRepository<UserProfile, UserProfileEntity, String> { - private final static Logger logger = LoggerFactory.getLogger(UserProfileRepository.class); - - public UserProfileRepository(Class<UserProfile> thriftGenericClass, Class<UserProfileEntity> dbEntityGenericClass) { - super(thriftGenericClass, dbEntityGenericClass); - } - - @Override - public List<UserProfile> select(String query, int offset, int limit) { - throw new UnsupportedOperationException("Due to performance overheads this method is not supported. Instead use" + - " UserProfileSummaryRepository"); - } - - public UserProfile getUserProfileByIdAndGateWay(String userId, String gatewayId) { - - UserProfile userProfile = null; - - Map<String, Object> queryParam = new HashMap<String, Object>(); - queryParam.put(UserProfile._Fields.USER_ID.getFieldName(), userId); - queryParam.put(UserProfile._Fields.GATEWAY_ID.getFieldName(), gatewayId); - List<UserProfile> resultList = select(QueryConstants.FIND_USER_PROFILE_BY_USER_ID, 0, 1, queryParam); - - if (resultList != null && resultList.size() > 0) - userProfile = resultList.get(0); - - - return userProfile; - } - - public List<UserProfile> getAllUserProfilesInGateway(String gatewayId, int offset, int limit) { - - Map<String, Object> queryParam = new HashMap<String, Object>(); - queryParam.put(UserProfile._Fields.GATEWAY_ID.getFieldName(), gatewayId); - - List<UserProfile> resultList = select(QueryConstants.FIND_ALL_USER_PROFILES_BY_GATEWAY_ID, limit, offset, queryParam); - - return resultList; - } - - public UserProfile getUserProfileByNameAndGateWay(String name, String gatewayId) { - - UserProfile userProfile = null; - - Map<String, Object> queryParam = new HashMap<String, Object>(); - queryParam.put(UserProfile._Fields.USER_NAME.getFieldName(), name); - queryParam.put(UserProfile._Fields.GATEWAY_ID.getFieldName(), gatewayId); - List<UserProfile> resultList = select(QueryConstants.FIND_USER_PROFILE_BY_USER_NAME, 0, 1, queryParam); - - if (resultList != null && resultList.size() > 0) - userProfile = resultList.get(0); - - - return userProfile; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Committer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Committer.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Committer.java deleted file mode 100644 index 07f8244..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Committer.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * 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.registry.core.utils; - -@FunctionalInterface -public interface Committer<T, R> { - - R commit(T t); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAConstants.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAConstants.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAConstants.java deleted file mode 100644 index f2bb888..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAConstants.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * 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.registry.core.utils; -public class JPAConstants { - public static final String KEY_JDBC_URL = "user.profile.catalog.registry.jdbc.url"; - public static final String KEY_JDBC_USER = "user.profile.catalog.registry.jdbc.user"; - public static final String KEY_JDBC_PASSWORD = "user.profile.catalog.registry.jdbc.password"; - public static final String KEY_JDBC_DRIVER = "user.profile.catalog.registry.jdbc.driver"; - public static final String KEY_DERBY_START_ENABLE = "user.profile.catalog.start.derby.server.mode"; - public static final String VALIDATION_QUERY = "user.profile.catalog.validationQuery"; - public static final String JPA_CACHE_SIZE = "user.profile.catalog.jpa.cache.size"; - public static final String ENABLE_CACHING = "user.profile.catalog.cache.enable"; -} http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAUtils.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAUtils.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAUtils.java deleted file mode 100644 index 119aa2c..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/JPAUtils.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * 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.registry.core.utils; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.*; -import java.util.HashMap; -import java.util.Map; - -public class JPAUtils { - private final static Logger logger = LoggerFactory.getLogger(JPAUtils.class); - private static final String PERSISTENCE_UNIT_NAME = "user_profile_catalog"; - @PersistenceUnit(unitName = "user_profile_catalog") - protected static EntityManagerFactory factory; - @PersistenceContext(unitName = "user_profile_catalog") - private static EntityManager entityManager; - - public static EntityManager getEntityManager(){ - - if (factory == null) { - //FIXME - String connectionProperties = "DriverClassName=" + Utils.getJDBCDriver() + "," + "Url=" + - Utils.getJDBCURL() + "?autoReconnect=true," + - "Username=" + Utils.getJDBCUser() + "," + "Password=" + Utils.getJDBCPassword() + - ",validationQuery=" + Utils.getValidationQuery(); - logger.info(connectionProperties); - Map<String, String> properties = new HashMap<String, String>(); - properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource"); - properties.put("openjpa.ConnectionProperties", connectionProperties); - properties.put("openjpa.DynamicEnhancementAgent", "true"); - properties.put("openjpa.RuntimeUnenhancedClasses", "warn"); - properties.put("openjpa.RemoteCommitProvider", "sjvm"); - properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO"); - properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); - properties.put("openjpa.jdbc.QuerySQLCache", "false"); - properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," + - " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true"); - factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties); - } - - entityManager = factory.createEntityManager(); - return entityManager; - } - - public static <R> R execute(Committer<EntityManager, R> committer){ - EntityManager entityManager = JPAUtils.getEntityManager(); - try { - entityManager.getTransaction().begin(); - R r = committer.commit(entityManager); - entityManager.getTransaction().commit(); - return r; - }finally { - if (entityManager != null && entityManager.isOpen()) { - if (entityManager.getTransaction().isActive()) { - entityManager.getTransaction().rollback(); - } - entityManager.close(); - } - } - } - - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java deleted file mode 100644 index 9189460..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * 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.registry.core.utils; - -import org.dozer.DozerBeanMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ObjectMapperSingleton extends DozerBeanMapper{ - private final static Logger logger = LoggerFactory.getLogger(ObjectMapperSingleton.class); - - private static ObjectMapperSingleton instance; - - private ObjectMapperSingleton(){} - - public static ObjectMapperSingleton getInstance(){ - if(instance == null) - instance = new ObjectMapperSingleton(); - return instance; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java deleted file mode 100644 index 171317e..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apache.airavata.registry.core.utils; - -import org.apache.airavata.model.user.UserProfile; - -/** - * Created by abhij on 11/11/2016. - */ -public interface QueryConstants { - - - - String FIND_USER_PROFILE_BY_USER_ID = "SELECT u FROM UserProfileEntity u " + - "where u.userId LIKE :" + UserProfile._Fields.USER_ID.getFieldName() + " " + - "AND u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + ""; - - String FIND_ALL_USER_PROFILES_BY_GATEWAY_ID = "SELECT u FROM UserProfileEntity u " + - "where u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + ""; - - String FIND_USER_PROFILE_BY_USER_NAME = "SELECT u FROM UserProfileEntity u " + - "where u.userId LIKE :" + UserProfile._Fields.USER_NAME.getFieldName() + " " + - "AND u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + ""; -} http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Utils.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Utils.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Utils.java deleted file mode 100644 index 7b5c60a..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/registry/core/utils/Utils.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * - * 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.registry.core.utils; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.registry.core.utils.JPAConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; - - -public class Utils { - private final static Logger logger = LoggerFactory.getLogger(Utils.class); - - public static String getJDBCFullURL(){ - String jdbcUrl = getJDBCURL(); - String jdbcUser = getJDBCUser(); - String jdbcPassword = getJDBCPassword(); - jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; - return jdbcUrl; - } - - public static String getJDBCURL(){ - try { - return ServerSettings.getSetting(JPAConstants.KEY_JDBC_URL); - } catch (ApplicationSettingsException e) { - logger.error(e.getMessage(), e); - return null; - } - } - - public static String getHost(){ - try{ - String jdbcURL = getJDBCURL(); - String cleanURI = jdbcURL.substring(5); - URI uri = URI.create(cleanURI); - return uri.getHost(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return null; - } - } - - public static int getPort(){ - try{ - String jdbcURL = getJDBCURL(); - String cleanURI = jdbcURL.substring(5); - URI uri = URI.create(cleanURI); - return uri.getPort(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return -1; - } - } - - public static int getJPACacheSize (){ - try { - String cache = ServerSettings.getSetting(JPAConstants.JPA_CACHE_SIZE, "5000"); - return Integer.parseInt(cache); - }catch (Exception e){ - logger.error(e.getMessage(), e); - return -1; - } - } - - public static String isCachingEnabled (){ - try { - return ServerSettings.getSetting(JPAConstants.ENABLE_CACHING, "true"); - }catch (Exception e){ - logger.error(e.getMessage(), e); - return "true"; - } - } - - public static String getDBType(){ - try{ - String jdbcURL = getJDBCURL(); - String cleanURI = jdbcURL.substring(5); - URI uri = URI.create(cleanURI); - return uri.getScheme(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return null; - } - } - - public static boolean isDerbyStartEnabled(){ - try { - String s = ServerSettings.getSetting(JPAConstants.KEY_DERBY_START_ENABLE); - if("true".equals(s)){ - return true; - } - } catch (ApplicationSettingsException e) { - logger.error(e.getMessage(), e); - return false; - } - return false; - } - - public static String getJDBCUser(){ - try { - return ServerSettings.getSetting(JPAConstants.KEY_JDBC_USER); - } catch (ApplicationSettingsException e) { - logger.error(e.getMessage(), e); - return null; - } - } - - public static String getValidationQuery(){ - try { - return ServerSettings.getSetting(JPAConstants.VALIDATION_QUERY); - } catch (ApplicationSettingsException e) { - logger.error(e.getMessage(), e); - return null; - } - } - - public static String getJDBCPassword(){ - try { - return ServerSettings.getSetting(JPAConstants.KEY_JDBC_PASSWORD); - } catch (ApplicationSettingsException e) { - logger.error(e.getMessage(), e); - return null; - } - - } - - public static String getJDBCDriver(){ - try { - return ServerSettings.getSetting(JPAConstants.KEY_JDBC_DRIVER); - } catch (ApplicationSettingsException e) { - logger.error(e.getMessage(), e); - return null; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/UserProfileRegistryException.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/UserProfileRegistryException.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/UserProfileRegistryException.java new file mode 100644 index 0000000..db6c391 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/UserProfileRegistryException.java @@ -0,0 +1,28 @@ +/* + * + * 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.user.registry.core; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UserProfileRegistryException extends Exception { + private final static Logger logger = LoggerFactory.getLogger(UserProfileRegistryException.class); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/NSFDemographicsEntity.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/NSFDemographicsEntity.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/NSFDemographicsEntity.java new file mode 100644 index 0000000..ccb4625 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/NSFDemographicsEntity.java @@ -0,0 +1,94 @@ +/* + * + * 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.user.registry.core.entities; + +import javax.persistence.*; +import java.util.List; + +@Entity +@Table(name = "NSF_DEMOGRAPHIC") +public class NSFDemographicsEntity { + private String airavataInternalUserId; + private String gender; + private List<String> ethnicities; + private List<String> races; + private List<String> disabilities; + private UserProfileEntity userProfile; + + @Id + @Column(name = "AIRAVATA_INTERNAL_USER_ID") + public String getAiravataInternalUserId() { + return airavataInternalUserId; + } + + public void setAiravataInternalUserId(String userId) { + this.airavataInternalUserId = userId; + } + + @Column(name = "GENDER") + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + @ElementCollection + @CollectionTable(name="NSF_DEMOGRAPHIC_ETHNICITY", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getEthnicities() { + return ethnicities; + } + + public void setEthnicities(List<String> ethnicities) { + this.ethnicities = ethnicities; + } + + @ElementCollection + @CollectionTable(name="NSF_DEMOGRAPHIC_RACE", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getRaces() { + return races; + } + + public void setRaces(List<String> races) { + this.races = races; + } + + @ElementCollection + @CollectionTable(name="NSF_DEMOGRAPHIC_DISABILITY", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getDisabilities() { + return disabilities; + } + + public void setDisabilities(List<String> disabilities) { + this.disabilities = disabilities; + } + + @OneToOne(targetEntity = UserProfileEntity.class, cascade = CascadeType.ALL) + @PrimaryKeyJoinColumn(name = "AIRAVATA_INTERNAL_USER_ID", referencedColumnName = "AIRAVATA_INTERNAL_USER_ID") + public UserProfileEntity getUserProfile() { + return userProfile; + } + + public void setUserProfile(UserProfileEntity userProfile) { + this.userProfile = userProfile; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/UserProfileEntity.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/UserProfileEntity.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/UserProfileEntity.java new file mode 100644 index 0000000..6fe0700 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/entities/UserProfileEntity.java @@ -0,0 +1,247 @@ +/* + * + * 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.user.registry.core.entities; + +import javax.persistence.*; +import java.util.List; + +@Entity +@Table(name="USER_PROFILE") +public class UserProfileEntity { + private String airavataInternalUserId; + private String userId; + private String gatewayId; + private String userModelVersion; + private String userName; + private String orcidId; + private String country; + private String homeOrganization; + private String orginationAffiliation; + private long creationTime; + private long lastAccessTime; + private long validUntil; + private String state; + private String comments; + private List<String> labeledURI; + private String gpgKey; + private String timeZone; + + private List<String> nationality; + private List<String> emails; + private List<String> phones; + private NSFDemographicsEntity nsfDemographics; + + @Id + @Column(name = "AIRAVATA_INTERNAL_USER_ID") + public String getAiravataInternalUserId() { + return airavataInternalUserId; + } + + public void setAiravataInternalUserId(String id) { + this.airavataInternalUserId = id; + } + + @Column(name = "USER_ID") + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + @Column(name = "GATEWAY_ID") + public String getGatewayId() { + return gatewayId; + } + + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + + @Column(name = "USER_MODEL_VERSION") + public String getUserModelVersion() { + return userModelVersion; + } + + public void setUserModelVersion(String userModelVersion) { + this.userModelVersion = userModelVersion; + } + + @ElementCollection + @CollectionTable(name="USER_PROFILE_EMAIL", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getEmails() { + return emails; + } + + public void setEmails(List<String> emails) { + this.emails = emails; + } + + @Column(name = "USER_NAME") + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @Column(name = "ORCID_ID") + public String getOrcidId() { + return orcidId; + } + + public void setOrcidId(String orcidId) { + this.orcidId = orcidId; + } + + @ElementCollection + @CollectionTable(name="USER_PROFILE_PHONE", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getPhones() { + return phones; + } + + public void setPhones(List<String> phones) { + this.phones = phones; + } + + @Column(name = "COUNTRY") + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + @ElementCollection + @CollectionTable(name="USER_PROFILE_NATIONALITY", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getNationality() { + return nationality; + } + + public void setNationality(List<String> nationality) { + this.nationality = nationality; + } + + @Column(name = "HOME_ORGANIZATION") + public String getHomeOrganization() { + return homeOrganization; + } + + public void setHomeOrganization(String homeOrganization) { + this.homeOrganization = homeOrganization; + } + + @Column(name = "ORIGINATION_AFFILIATION") + public String getOrginationAffiliation() { + return orginationAffiliation; + } + + public void setOrginationAffiliation(String orginationAffiliation) { + this.orginationAffiliation = orginationAffiliation; + } + + @Column(name="CREATION_TIME") + public long getCreationTime() { + return creationTime; + } + + public void setCreationTime(long creationTime) { + this.creationTime = creationTime; + } + + @Column(name = "LAST_ACCESS_TIME") + public long getLastAccessTime() { + return lastAccessTime; + } + + public void setLastAccessTime(long lastAccessTime) { + this.lastAccessTime = lastAccessTime; + } + + @Column(name = "VALID_UNTIL") + public long getValidUntil() { + return validUntil; + } + + public void setValidUntil(long validUntil) { + this.validUntil = validUntil; + } + + @Column(name = "STATE") + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + @Lob + @Column(name = "COMMENTS") + public String getComments() { + return comments; + } + + public void setComments(String comments) { + this.comments = comments; + } + + @ElementCollection + @CollectionTable(name="USER_PROFILE_LABELED_URI", joinColumns = @JoinColumn(name="AIRAVATA_INTERNAL_USER_ID")) + public List<String> getLabeledURI() { + return labeledURI; + } + + public void setLabeledURI(List<String> labeledURI) { + this.labeledURI = labeledURI; + } + + @Lob + @Column(name = "GPG_KEY") + public String getGpgKey() { + return gpgKey; + } + + public void setGpgKey(String gpgKey) { + this.gpgKey = gpgKey; + } + + @Column(name = "TIME_ZONE") + public String getTimeZone() { + return timeZone; + } + + public void setTimeZone(String timeZone) { + this.timeZone = timeZone; + } + + @OneToOne(targetEntity = NSFDemographicsEntity.class, cascade = CascadeType.ALL, mappedBy = "userProfile") + public NSFDemographicsEntity getNsfDemographics() { + return nsfDemographics; + } + + public void setNsfDemographics(NSFDemographicsEntity nsfDemographics) { + this.nsfDemographics = nsfDemographics; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/AbstractRepository.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/AbstractRepository.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/AbstractRepository.java new file mode 100644 index 0000000..f61aa3b --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/AbstractRepository.java @@ -0,0 +1,98 @@ +/* + * + * 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.user.registry.core.repositories; + +import org.apache.airavata.user.registry.core.utils.JPAUtils; +import org.apache.airavata.user.registry.core.utils.ObjectMapperSingleton; +import org.dozer.Mapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public abstract class AbstractRepository<T, E, Id> { + private final static Logger logger = LoggerFactory.getLogger(AbstractRepository.class); + + private Class<T> thriftGenericClass; + private Class<E> dbEntityGenericClass; + + public AbstractRepository(Class<T> thriftGenericClass, Class<E> dbEntityGenericClass) { + this.thriftGenericClass = thriftGenericClass; + this.dbEntityGenericClass = dbEntityGenericClass; + } + + public T create(T t) { + return update(t); + } + + public T update(T t) { + Mapper mapper = ObjectMapperSingleton.getInstance(); + E entity = mapper.map(t, dbEntityGenericClass); + E persistedCopy = JPAUtils.execute(entityManager -> entityManager.merge(entity)); + return mapper.map(persistedCopy, thriftGenericClass); + } + + public boolean delete(Id id) { + JPAUtils.execute(entityManager -> { + E entity = entityManager.find(dbEntityGenericClass, id); + entityManager.remove(entity); + return entity; + }); + return true; + } + + public T get(Id id) { + E entity = JPAUtils.execute(entityManager -> entityManager + .find(dbEntityGenericClass, id)); + Mapper mapper = ObjectMapperSingleton.getInstance(); + return mapper.map(entity, thriftGenericClass); + } + + public List<T> select(String query, int limit, int offset) { + List resultSet = (List) JPAUtils.execute(entityManager -> entityManager.createQuery(query).setFirstResult(offset) + .setMaxResults(offset).getResultList()); + Mapper mapper = ObjectMapperSingleton.getInstance(); + List<T> gatewayList = new ArrayList<>(); + resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass))); + return gatewayList; + } + + public List<T> select(String query, int limit, int offset, Map<String, Object> queryParams) { + List resultSet = (List) JPAUtils.execute(entityManager -> { + Query jpaQuery = entityManager.createQuery(query); + + for (Map.Entry<String, Object> entry : queryParams.entrySet()) { + + jpaQuery.setParameter(entry.getKey(), entry.getValue()); + } + + return jpaQuery.setFirstResult(offset).setMaxResults(limit).getResultList(); + + }); + Mapper mapper = ObjectMapperSingleton.getInstance(); + List<T> gatewayList = new ArrayList<>(); + resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass))); + return gatewayList; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/UserProfileRepository.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/UserProfileRepository.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/UserProfileRepository.java new file mode 100644 index 0000000..07965e5 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/repositories/UserProfileRepository.java @@ -0,0 +1,87 @@ +/* + * + * 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.user.registry.core.repositories; + +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.user.registry.core.entities.UserProfileEntity; +import org.apache.airavata.user.registry.core.utils.QueryConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UserProfileRepository extends AbstractRepository<UserProfile, UserProfileEntity, String> { + private final static Logger logger = LoggerFactory.getLogger(UserProfileRepository.class); + + public UserProfileRepository(Class<UserProfile> thriftGenericClass, Class<UserProfileEntity> dbEntityGenericClass) { + super(thriftGenericClass, dbEntityGenericClass); + } + + @Override + public List<UserProfile> select(String query, int offset, int limit) { + throw new UnsupportedOperationException("Due to performance overheads this method is not supported. Instead use" + + " UserProfileSummaryRepository"); + } + + public UserProfile getUserProfileByIdAndGateWay(String userId, String gatewayId) { + + UserProfile userProfile = null; + + Map<String, Object> queryParam = new HashMap<String, Object>(); + queryParam.put(UserProfile._Fields.USER_ID.getFieldName(), userId); + queryParam.put(UserProfile._Fields.GATEWAY_ID.getFieldName(), gatewayId); + List<UserProfile> resultList = select(QueryConstants.FIND_USER_PROFILE_BY_USER_ID, 0, 1, queryParam); + + if (resultList != null && resultList.size() > 0) + userProfile = resultList.get(0); + + + return userProfile; + } + + public List<UserProfile> getAllUserProfilesInGateway(String gatewayId, int offset, int limit) { + + Map<String, Object> queryParam = new HashMap<String, Object>(); + queryParam.put(UserProfile._Fields.GATEWAY_ID.getFieldName(), gatewayId); + + List<UserProfile> resultList = select(QueryConstants.FIND_ALL_USER_PROFILES_BY_GATEWAY_ID, limit, offset, queryParam); + + return resultList; + } + + public UserProfile getUserProfileByNameAndGateWay(String name, String gatewayId) { + + UserProfile userProfile = null; + + Map<String, Object> queryParam = new HashMap<String, Object>(); + queryParam.put(UserProfile._Fields.USER_NAME.getFieldName(), name); + queryParam.put(UserProfile._Fields.GATEWAY_ID.getFieldName(), gatewayId); + List<UserProfile> resultList = select(QueryConstants.FIND_USER_PROFILE_BY_USER_NAME, 0, 1, queryParam); + + if (resultList != null && resultList.size() > 0) + userProfile = resultList.get(0); + + + return userProfile; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Committer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Committer.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Committer.java new file mode 100644 index 0000000..fe96ca9 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Committer.java @@ -0,0 +1,27 @@ +/* + * + * 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.user.registry.core.utils; + +@FunctionalInterface +public interface Committer<T, R> { + + R commit(T t); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java new file mode 100644 index 0000000..8efb965 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java @@ -0,0 +1,32 @@ +/* + * + * 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.user.registry.core.utils; +public class JPAConstants { + public static final String KEY_JDBC_URL = "user.profile.catalog.registry.jdbc.url"; + public static final String KEY_JDBC_USER = "user.profile.catalog.registry.jdbc.user"; + public static final String KEY_JDBC_PASSWORD = "user.profile.catalog.registry.jdbc.password"; + public static final String KEY_JDBC_DRIVER = "user.profile.catalog.registry.jdbc.driver"; + public static final String KEY_DERBY_START_ENABLE = "user.profile.catalog.start.derby.server.mode"; + public static final String VALIDATION_QUERY = "user.profile.catalog.validationQuery"; + public static final String JPA_CACHE_SIZE = "user.profile.catalog.jpa.cache.size"; + public static final String ENABLE_CACHING = "user.profile.catalog.cache.enable"; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAUtils.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAUtils.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAUtils.java new file mode 100644 index 0000000..2961524 --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAUtils.java @@ -0,0 +1,83 @@ +/* + * + * 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.user.registry.core.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.*; +import java.util.HashMap; +import java.util.Map; + +public class JPAUtils { + private final static Logger logger = LoggerFactory.getLogger(JPAUtils.class); + private static final String PERSISTENCE_UNIT_NAME = "user_profile_catalog"; + @PersistenceUnit(unitName = "user_profile_catalog") + protected static EntityManagerFactory factory; + @PersistenceContext(unitName = "user_profile_catalog") + private static EntityManager entityManager; + + public static EntityManager getEntityManager(){ + + if (factory == null) { + //FIXME + String connectionProperties = "DriverClassName=" + Utils.getJDBCDriver() + "," + "Url=" + + Utils.getJDBCURL() + "?autoReconnect=true," + + "Username=" + Utils.getJDBCUser() + "," + "Password=" + Utils.getJDBCPassword() + + ",validationQuery=" + Utils.getValidationQuery(); + logger.info(connectionProperties); + Map<String, String> properties = new HashMap<String, String>(); + properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource"); + properties.put("openjpa.ConnectionProperties", connectionProperties); + properties.put("openjpa.DynamicEnhancementAgent", "true"); + properties.put("openjpa.RuntimeUnenhancedClasses", "warn"); + properties.put("openjpa.RemoteCommitProvider", "sjvm"); + properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO"); + properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); + properties.put("openjpa.jdbc.QuerySQLCache", "false"); + properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," + + " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true"); + factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties); + } + + entityManager = factory.createEntityManager(); + return entityManager; + } + + public static <R> R execute(Committer<EntityManager, R> committer){ + EntityManager entityManager = JPAUtils.getEntityManager(); + try { + entityManager.getTransaction().begin(); + R r = committer.commit(entityManager); + entityManager.getTransaction().commit(); + return r; + }finally { + if (entityManager != null && entityManager.isOpen()) { + if (entityManager.getTransaction().isActive()) { + entityManager.getTransaction().rollback(); + } + entityManager.close(); + } + } + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/ObjectMapperSingleton.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/ObjectMapperSingleton.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/ObjectMapperSingleton.java new file mode 100644 index 0000000..e7324eb --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/ObjectMapperSingleton.java @@ -0,0 +1,39 @@ +/* + * + * 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.user.registry.core.utils; + +import org.dozer.DozerBeanMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ObjectMapperSingleton extends DozerBeanMapper{ + private final static Logger logger = LoggerFactory.getLogger(ObjectMapperSingleton.class); + + private static ObjectMapperSingleton instance; + + private ObjectMapperSingleton(){} + + public static ObjectMapperSingleton getInstance(){ + if(instance == null) + instance = new ObjectMapperSingleton(); + return instance; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/QueryConstants.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/QueryConstants.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/QueryConstants.java new file mode 100644 index 0000000..773dc3f --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/QueryConstants.java @@ -0,0 +1,22 @@ +package org.apache.airavata.user.registry.core.utils; + +import org.apache.airavata.model.user.UserProfile; + +/** + * Created by abhij on 11/11/2016. + */ +public interface QueryConstants { + + + + String FIND_USER_PROFILE_BY_USER_ID = "SELECT u FROM UserProfileEntity u " + + "where u.userId LIKE :" + UserProfile._Fields.USER_ID.getFieldName() + " " + + "AND u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + ""; + + String FIND_ALL_USER_PROFILES_BY_GATEWAY_ID = "SELECT u FROM UserProfileEntity u " + + "where u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + ""; + + String FIND_USER_PROFILE_BY_USER_NAME = "SELECT u FROM UserProfileEntity u " + + "where u.userId LIKE :" + UserProfile._Fields.USER_NAME.getFieldName() + " " + + "AND u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + ""; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Utils.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Utils.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Utils.java new file mode 100644 index 0000000..b349c8d --- /dev/null +++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/Utils.java @@ -0,0 +1,155 @@ +/* + * + * 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.user.registry.core.utils; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; + + +public class Utils { + private final static Logger logger = LoggerFactory.getLogger(Utils.class); + + public static String getJDBCFullURL(){ + String jdbcUrl = getJDBCURL(); + String jdbcUser = getJDBCUser(); + String jdbcPassword = getJDBCPassword(); + jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword; + return jdbcUrl; + } + + public static String getJDBCURL(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_URL); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getHost(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getHost(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static int getPort(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getPort(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return -1; + } + } + + public static int getJPACacheSize (){ + try { + String cache = ServerSettings.getSetting(JPAConstants.JPA_CACHE_SIZE, "5000"); + return Integer.parseInt(cache); + }catch (Exception e){ + logger.error(e.getMessage(), e); + return -1; + } + } + + public static String isCachingEnabled (){ + try { + return ServerSettings.getSetting(JPAConstants.ENABLE_CACHING, "true"); + }catch (Exception e){ + logger.error(e.getMessage(), e); + return "true"; + } + } + + public static String getDBType(){ + try{ + String jdbcURL = getJDBCURL(); + String cleanURI = jdbcURL.substring(5); + URI uri = URI.create(cleanURI); + return uri.getScheme(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static boolean isDerbyStartEnabled(){ + try { + String s = ServerSettings.getSetting(JPAConstants.KEY_DERBY_START_ENABLE); + if("true".equals(s)){ + return true; + } + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return false; + } + return false; + } + + public static String getJDBCUser(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_USER); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getValidationQuery(){ + try { + return ServerSettings.getSetting(JPAConstants.VALIDATION_QUERY); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } + + public static String getJDBCPassword(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_PASSWORD); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + + } + + public static String getJDBCDriver(){ + try { + return ServerSettings.getSetting(JPAConstants.KEY_JDBC_DRIVER); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + return null; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-core/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/resources/META-INF/persistence.xml b/modules/user-profile/user-profile-core/src/main/resources/META-INF/persistence.xml index e786941..4791c67 100644 --- a/modules/user-profile/user-profile-core/src/main/resources/META-INF/persistence.xml +++ b/modules/user-profile/user-profile-core/src/main/resources/META-INF/persistence.xml @@ -22,8 +22,8 @@ <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="user_profile_catalog"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> - <class>org.apache.airavata.registry.core.entities.UserProfileEntity</class> - <class>org.apache.airavata.registry.core.entities.NSFDemographicsEntity</class> + <class>org.apache.airavata.user.registry.core.entities.UserProfileEntity</class> + <class>org.apache.airavata.user.registry.core.entities.NSFDemographicsEntity</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> </persistence-unit> </persistence> http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-service/pom.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/pom.xml b/modules/user-profile/user-profile-service/pom.xml index 0839735..4265697 100644 --- a/modules/user-profile/user-profile-service/pom.xml +++ b/modules/user-profile/user-profile-service/pom.xml @@ -24,6 +24,11 @@ <artifactId>user-profile-stubs</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>user-profile-core</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/e0f63bcb/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServiceHandler.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServiceHandler.java b/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServiceHandler.java index 379f9cb..ddefbc7 100644 --- a/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServiceHandler.java +++ b/modules/user-profile/user-profile-service/src/main/java/org/apache/airavata/user/profile/server/UserProfileServiceHandler.java @@ -21,8 +21,8 @@ package org.apache.airavata.user.profile.server; import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity; -import org.apache.airavata.registry.core.repositories.workspacecatalog.UserProfileRepository; +import org.apache.airavata.user.registry.core.entities.UserProfileEntity; +import org.apache.airavata.user.registry.core.repositories.UserProfileRepository; import org.apache.airavata.userprofile.cpi.UserProfileService; import org.apache.airavata.userprofile.cpi.exception.UserProfileServiceException; import org.apache.thrift.TException;
