http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftDeserializer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftDeserializer.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftDeserializer.java deleted file mode 100644 index 256b0e6..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftDeserializer.java +++ /dev/null @@ -1,151 +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.userprofile.core; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.node.JsonNodeType; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.type.TypeFactory; -import com.google.common.base.CaseFormat; -import org.apache.thrift.TBase; -import org.apache.thrift.TException; -import org.apache.thrift.TFieldIdEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.util.Iterator; -import java.util.Map; - -/** - * This abstract class represents a generic de-serializer for converting JSON to Thrift-based entities. - * - * @param <E> An implementation of the {@link org.apache.thrift.TFieldIdEnum} interface. - * @param <T> An implementation of the {@link org.apache.thrift.TBase} interface. - */ -public abstract class AbstractThriftDeserializer<E extends TFieldIdEnum, T extends TBase<T, E>> extends JsonDeserializer<T> { - - private static Logger log = LoggerFactory.getLogger(AbstractThriftDeserializer.class); - - @Override - public T deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { - final T instance = newInstance(); - final ObjectMapper mapper = (ObjectMapper)jp.getCodec(); - final ObjectNode rootNode = (ObjectNode)mapper.readTree(jp); - final Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.fields(); - - while(iterator.hasNext()) { - final Map.Entry<String, JsonNode> currentField = iterator.next(); - try { - /* - * If the current node is not a null value, process it. Otherwise, - * skip it. Jackson will treat the null as a 0 for primitive - * number types, which in turn will make Thrift think the field - * has been set. Also we ignore the MongoDB specific _id field - */ - if(!currentField.getKey().equalsIgnoreCase("_id") - && currentField.getValue().getNodeType() != JsonNodeType.NULL) { - final E field = getField(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, currentField.getKey())); - final JsonParser parser = currentField.getValue().traverse(); - parser.setCodec(mapper); - final Object value = mapper.readValue(parser, generateValueType(instance, field)); - if(value != null) { - log.debug(String.format("Field %s produced value %s of type %s.", - currentField.getKey(), value, value.getClass().getName())); - instance.setFieldValue(field, value); - } else { - log.debug("Field {} contains a null value. Skipping...", currentField.getKey()); - } - } else { - log.debug("Field {} contains a null value. Skipping...", currentField.getKey()); - } - } catch (final NoSuchFieldException | IllegalArgumentException e) { - log.error("Unable to de-serialize field '{}'.", currentField.getKey(), e); - ctxt.mappingException(e.getMessage()); - } - } - - try { - // Validate that the instance contains all required fields. - validate(instance); - } catch (final TException e) { - log.error("Unable to deserialize JSON {} to type {} : error: {}", jp.getValueAsString(), instance.getClass().getName(), e.getMessage()); - ctxt.mappingException(e.getMessage()); - } - - return instance; - } - - /** - * Returns the {@code <E>} enumerated value that represents the target - * field in the Thrift entity referenced in the JSON document. - * @param fieldName The name of the Thrift entity target field. - * @return The {@code <E>} enumerated value that represents the target - * field in the Thrift entity referenced in the JSON document. - */ - protected abstract E getField(String fieldName); - - /** - * Creates a new instance of the Thrift entity class represented by this deserializer. - * @return A new instance of the Thrift entity class represented by this deserializer. - */ - protected abstract T newInstance(); - - /** - * Validates that the Thrift entity instance contains all required fields after deserialization. - * @param instance A Thrift entity instance. - * @throws org.apache.thrift.TException if unable to validate the instance. - */ - protected abstract void validate(T instance) throws TException; - - /** - * Generates a {@link JavaType} that matches the target Thrift field represented by the provided - * {@code <E>} enumerated value. If the field's type includes generics, the generics will - * be added to the generated {@link JavaType} to support proper conversion. - * @param thriftInstance The Thrift-generated class instance that will be converted to/from JSON. - * @param field A {@code <E>} enumerated value that represents a field in a Thrift-based entity. - * @return The {@link JavaType} representation of the type associated with the field. - * @throws NoSuchFieldException if unable to determine the field's type. - * @throws SecurityException if unable to determine the field's type. - */ - protected JavaType generateValueType(final T thriftInstance, final E field) throws NoSuchFieldException, SecurityException { - final TypeFactory typeFactory = TypeFactory.defaultInstance(); - - final Field declaredField = thriftInstance.getClass().getDeclaredField(field.getFieldName()); - if(declaredField.getType().equals(declaredField.getGenericType())) { - log.debug("Generating JavaType for type '{}'.", declaredField.getType()); - return typeFactory.constructType(declaredField.getType()); - } else { - final ParameterizedType type = (ParameterizedType)declaredField.getGenericType(); - final Class<?>[] parameterizedTypes = new Class<?>[type.getActualTypeArguments().length]; - for(int i=0; i<type.getActualTypeArguments().length; i++) { - parameterizedTypes[i] = (Class<?>)type.getActualTypeArguments()[i]; - } - log.debug("Generating JavaType for type '{}' with generics '{}'", declaredField.getType(), parameterizedTypes); - return typeFactory.constructParametricType(declaredField.getType(), parameterizedTypes); - } - } - -}
http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftSerializer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftSerializer.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftSerializer.java deleted file mode 100644 index d9e19ab..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/AbstractThriftSerializer.java +++ /dev/null @@ -1,122 +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.userprofile.core; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.google.common.base.CaseFormat; -import org.apache.thrift.TBase; -import org.apache.thrift.TFieldIdEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Collection; - -/** - * This abstract class represents a generic serializer for converting Thrift-based entities - * to JSON. - * - * @param <E> An implementation of the {@link org.apache.thrift.TFieldIdEnum} interface. - * @param <T> An implementation of the {@link org.apache.thrift.TBase} interface. - */ -public abstract class AbstractThriftSerializer<E extends TFieldIdEnum, T extends TBase<T, E>> - extends JsonSerializer<T> { - - private static final Logger log = LoggerFactory.getLogger(AbstractThriftSerializer.class); - - @Override - public Class<T> handledType() { - return getThriftClass(); - } - - @Override - public void serialize(final T value, final JsonGenerator jgen, final SerializerProvider provider) - throws IOException, JsonProcessingException { - jgen.writeStartObject(); - for(final E field : getFieldValues()) { - if(value.isSet(field)) { - final Object fieldValue = value.getFieldValue(field); - if(fieldValue != null) { - log.debug("Adding field {} to the JSON string...", - CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName()) - ); - - jgen.writeFieldName(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName())); - if(fieldValue instanceof Short) { - jgen.writeNumber((Short)fieldValue); - } else if(fieldValue instanceof Integer) { - jgen.writeNumber((Integer)fieldValue); - } else if(fieldValue instanceof Long) { - jgen.writeNumber((Long)fieldValue); - } else if(fieldValue instanceof Double) { - jgen.writeNumber((Double)fieldValue); - } else if(fieldValue instanceof Float) { - jgen.writeNumber((Float)fieldValue); - } else if(fieldValue instanceof Boolean) { - jgen.writeBoolean((Boolean)fieldValue); - } else if(fieldValue instanceof String) { - jgen.writeString(fieldValue.toString()); - } else if(fieldValue instanceof Collection) { - log.debug("Array opened for field {}.", - CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName()) - ); - jgen.writeStartArray(); - for(final Object arrayObject : (Collection<?>)fieldValue) { - jgen.writeObject(arrayObject); - } - jgen.writeEndArray(); - log.debug("Array closed for field {}.", - CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName()) - ); - } else { - jgen.writeObject(fieldValue); - } - } else { - log.debug("Skipping converting field {} to JSON: value is null!", - CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName()) - ); - } - } else { - log.debug("Skipping converting field {} to JSON: field has not been set!", - CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,field.getFieldName()) - ); - } - } - jgen.writeEndObject(); - } - - /** - * Returns an array of {@code <E>} enumerated values that represent the fields present in the - * Thrift class associated with this serializer. - * @return The array of {@code <E>} enumerated values that represent the fields present in the - * Thrift class. - */ - protected abstract E[] getFieldValues(); - - /** - * Returns the {@code <T>} implementation class associated with this serializer. - * @return The {@code <T>} implementation class - */ - protected abstract Class<T> getThriftClass(); -} http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/ModelConversionHelper.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/ModelConversionHelper.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/ModelConversionHelper.java deleted file mode 100644 index cae69a1..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/ModelConversionHelper.java +++ /dev/null @@ -1,77 +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.userprofile.core; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.module.SimpleModule; -import org.apache.airavata.model.user.UserProfile; -import org.apache.thrift.TBase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class ModelConversionHelper { - private final static Logger logger = LoggerFactory.getLogger(ModelConversionHelper.class); - private ObjectMapper objectMapper; - - public ModelConversionHelper(){ - init(); - } - - /** - * Private method to register the custom serializers and deserializers - */ - private void init() { - this.objectMapper = new ObjectMapper(); - SimpleModule module = new SimpleModule("UserProfileModule", - new Version(1, 0, 0, null, null, null)); - - module.addSerializer(UserProfile.class, new UserProfileSerializer()); - module.addDeserializer(UserProfile.class, new UserProfileDeserializer()); - - objectMapper.registerModule(module); - } - - /** - * Method to serialize a thrift object to json - * @param object - * @return - * @throws JsonProcessingException - */ - public String serializeObject(TBase object) throws JsonProcessingException { - String json = this.objectMapper.writeValueAsString(object); - return json; - } - - /** - * Method to deserialize a json to the thrift object - * @param clz - * @param json - * @return - * @throws IOException - */ - public TBase deserializeObject(Class<?> clz, String json) throws IOException { - return (TBase)this.objectMapper.readValue(json, clz); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/MongoUtil.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/MongoUtil.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/MongoUtil.java deleted file mode 100644 index 3cd3598..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/MongoUtil.java +++ /dev/null @@ -1,59 +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.userprofile.core; - -import com.mongodb.DB; -import com.mongodb.MongoClient; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MongoUtil { - private final static Logger logger = LoggerFactory.getLogger(MongoUtil.class); - - private static MongoClient mongoClient = null; - private static DB userProfileRegistry; - public static String USER_PROFILE_REGISTRY_NAME = "user-profile-registry"; - - public static MongoClient getMongoClient() throws ApplicationSettingsException { - if (mongoClient == null) { - String host = ServerSettings.getUserProfileMongodbHost(); - int port = ServerSettings.getUserProfileMongodbPort(); - mongoClient = new MongoClient(host, port); - logger.debug("New Mongo Client created with [" + host + "] and [" - + port + "]"); - } - return mongoClient; - } - - public static DB getUserProfileRegistry() throws ApplicationSettingsException { - if (userProfileRegistry == null) { - userProfileRegistry = getMongoClient().getDB(USER_PROFILE_REGISTRY_NAME); - } - return userProfileRegistry; - } - - public static void dropUserProfileRegistry() throws ApplicationSettingsException { - getMongoClient().dropDatabase(USER_PROFILE_REGISTRY_NAME); - logger.debug("Dropped User Profile Registry"); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImpl.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImpl.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImpl.java deleted file mode 100644 index 991f193..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImpl.java +++ /dev/null @@ -1,79 +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.userprofile.core; - -import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.userprofile.cpi.UserProfileCPI; -import org.apache.airavata.userprofile.cpi.UserProfileException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.UUID; - -public class UserProfileCPIImpl implements UserProfileCPI { - private final static Logger logger = LoggerFactory.getLogger(UserProfileCPIImpl.class); - - private UserProfileDao userProfileDao; - - public UserProfileCPIImpl() throws UserProfileException { - userProfileDao = new UserProfileDao(); - } - - @Override - public List<UserProfile> getAllUserProfilesInGateway(String gatewayId) throws UserProfileException { - return userProfileDao.getAllUserProfilesInGateway(gatewayId); - } - - @Override - public String createUserProfile(UserProfile userProfile) throws UserProfileException { - userProfile.setUserId(UUID.randomUUID().toString()); - // Setting user id to airavataInternalUserId. We don't distinguish these two at the moment. - userProfile.setAiravataInternalUserId(userProfile.getUserId()); - userProfileDao.createUserProfile(userProfile); - return userProfile.getUserId(); - } - - @Override - public boolean updateUserProfile(UserProfile userProfile) throws UserProfileException { - return userProfileDao.updateUserProfile(userProfile); - } - - @Override - public boolean deleteUserProfile(String userId) throws UserProfileException { - return userProfileDao.deleteUserProfile(userId); - } - - @Override - public UserProfile getUserProfileFromUserId(String userId) throws UserProfileException { - return userProfileDao.getUserProfileFromUserId(userId); - } - - @Override - public UserProfile getUserProfileFromUserName(String userName, String gatewayId) throws UserProfileException { - return userProfileDao.getUserProfileFromUserName(userName, gatewayId); - } - - @Override - public boolean userProfileExists(String userName, String gatewayId) throws UserProfileException { - return userProfileDao.userProfileExists(userName, gatewayId); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImplFactory.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImplFactory.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImplFactory.java deleted file mode 100644 index 532d382..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileCPIImplFactory.java +++ /dev/null @@ -1,43 +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.userprofile.core; - -import org.apache.airavata.userprofile.cpi.UserProfileException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UserProfileCPIImplFactory { - private final static Logger logger = LoggerFactory.getLogger(UserProfileCPIImplFactory.class); - - private static UserProfileCPIImpl userProfileCPIImpl; - - public static UserProfileCPIImpl getRegistry() throws UserProfileException { - try { - if (userProfileCPIImpl == null) { - userProfileCPIImpl = new UserProfileCPIImpl(); - } - } catch (Exception e) { - logger.error("Unable to create UserProfileCPIImpl instance", e); - throw new UserProfileException(e); - } - return userProfileCPIImpl; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDao.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDao.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDao.java deleted file mode 100644 index be3a78b..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDao.java +++ /dev/null @@ -1,164 +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.userprofile.core; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.mongodb.*; -import com.mongodb.util.JSON; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.userprofile.cpi.UserProfileException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class UserProfileDao { - private final static Logger logger = LoggerFactory.getLogger(UserProfileDao.class); - - private static final String USER_PROFILE_COLLECTION_NAME = "user-profiles"; - private DBCollection collection; - private ModelConversionHelper modelConversionHelper; - - private static final String USER_ID = "user_id"; - private static final String USER_NAME = "user_name"; - private static final String GATEWAY_ID = "gateway_id"; - - public UserProfileDao() throws UserProfileException { - try { - collection = MongoUtil.getUserProfileRegistry().getCollection(USER_PROFILE_COLLECTION_NAME); - } catch (ApplicationSettingsException e) { - throw new UserProfileException(e); - } - modelConversionHelper = new ModelConversionHelper(); - //collection.dropIndexes(); - initIndexes(); - } - - /** - * If indexes are already defined this will simply ignore them - */ - private void initIndexes(){ - // UserID is the primary key - collection.createIndex(new BasicDBObject(USER_ID, 1), new BasicDBObject("unique", true)); - // UserName and GatewayID combination is also makes a unique key - collection.createIndex(new BasicDBObject(USER_NAME, 1).append(GATEWAY_ID, 1), new BasicDBObject("unique", true)); - } - - public List<UserProfile> getAllUserProfilesInGateway(String gatewayId) throws UserProfileException { - List<UserProfile> userList = new ArrayList(); - DBCursor cursor = collection.find(); - for(DBObject document: cursor){ - try { - userList.add((UserProfile) modelConversionHelper.deserializeObject( - UserProfile.class, document.toString())); - } catch (IOException e) { - throw new UserProfileException(e); - } - } - return userList; - } - - public boolean createUserProfile(UserProfile userProfile) throws UserProfileException{ - try { - WriteResult result = collection.insert((DBObject) JSON.parse( - modelConversionHelper.serializeObject(userProfile))); - logger.debug("No of inserted results "+ result.getN()); - return true; - } catch (JsonProcessingException e) { - throw new UserProfileException(e); - } - } - - /** - * The following operation replaces the document with item equal to - * the given user id. The newly replaced document will only - * contain the the _id field and the fields in the replacement document. - * @param userProfile - * @throws org.apache.airavata.registry.cpi.UserProfileException - */ - public boolean updateUserProfile(UserProfile userProfile) throws UserProfileException{ - try { - DBObject query = BasicDBObjectBuilder.start().add( - USER_ID, userProfile.getUserId()).get(); - WriteResult result = collection.update(query, (DBObject) JSON.parse( - modelConversionHelper.serializeObject(userProfile))); - logger.debug("No of updated results "+ result.getN()); - return true; - } catch (JsonProcessingException e) { - throw new UserProfileException(e); - } - } - - public boolean deleteUserProfile(String userId) throws UserProfileException{ - DBObject query = BasicDBObjectBuilder.start().add( - USER_ID, userId).get(); - WriteResult result = collection.remove(query); - logger.debug("No of removed user profiles " + result.getN()); - return true; - } - - public UserProfile getUserProfileFromUserId(String userId) throws UserProfileException{ - try { - DBObject criteria = new BasicDBObject(USER_ID, userId); - DBObject doc = collection.findOne(criteria); - if(doc != null){ - String json = doc.toString(); - return (UserProfile)modelConversionHelper.deserializeObject( - UserProfile.class, json); - } - } catch (IOException e) { - throw new UserProfileException(e); - } - return null; - } - - public UserProfile getUserProfileFromUserName(String userName, String gatewayId) throws UserProfileException{ - try { - DBObject criteria = new BasicDBObject(USER_NAME, userName).append(GATEWAY_ID, gatewayId); - DBObject doc = collection.findOne(criteria); - if(doc != null){ - String json = doc.toString(); - return (UserProfile)modelConversionHelper.deserializeObject( - UserProfile.class, json); - } - } catch (IOException e) { - throw new UserProfileException(e); - } - return null; - } - - public boolean userProfileExists(String userName, String gatewayId) throws UserProfileException{ - try { - DBObject criteria = new BasicDBObject(USER_NAME, userName).append(GATEWAY_ID, gatewayId); - DBObject doc = collection.findOne(criteria); - if(doc != null){ - String json = doc.toString(); - return modelConversionHelper.deserializeObject(UserProfile.class, json) != null; - } - return false; - } catch (IOException e) { - throw new UserProfileException(e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDeserializer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDeserializer.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDeserializer.java deleted file mode 100644 index 4af0fc8..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileDeserializer.java +++ /dev/null @@ -1,64 +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.userprofile.core; - -import org.apache.airavata.model.user.UserProfile; -import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UserProfileDeserializer extends AbstractThriftDeserializer<UserProfile._Fields, UserProfile>{ - private final static Logger logger = LoggerFactory.getLogger(UserProfileDeserializer.class); - - /** - * Returns the {@code <E>} enumerated value that represents the target - * field in the Thrift entity referenced in the JSON document. - * - * @param fieldName The name of the Thrift entity target field. - * @return The {@code <E>} enumerated value that represents the target - * field in the Thrift entity referenced in the JSON document. - */ - @Override - protected UserProfile._Fields getField(String fieldName) { - return UserProfile._Fields.valueOf(fieldName); - } - - /** - * Creates a new instance of the Thrift entity class represented by this deserializer. - * - * @return A new instance of the Thrift entity class represented by this deserializer. - */ - @Override - protected UserProfile newInstance() { - return new UserProfile(); - } - - /** - * Validates that the Thrift entity instance contains all required fields after deserialization. - * - * @param instance A Thrift entity instance. - * @throws TException if unable to validate the instance. - */ - @Override - protected void validate(UserProfile instance) throws TException { - instance.validate(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileSerializer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileSerializer.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileSerializer.java deleted file mode 100644 index 0f20906..0000000 --- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/userprofile/core/UserProfileSerializer.java +++ /dev/null @@ -1,51 +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.userprofile.core; - -import org.apache.airavata.model.user.UserProfile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UserProfileSerializer extends AbstractThriftSerializer<UserProfile._Fields, UserProfile> { - private final static Logger logger = LoggerFactory.getLogger(UserProfileSerializer.class); - - /** - * Returns an array of {@code <E>} enumerated values that represent the fields present in the - * Thrift class associated with this serializer. - * - * @return The array of {@code <E>} enumerated values that represent the fields present in the - * Thrift class. - */ - @Override - protected UserProfile._Fields[] getFieldValues() { - return UserProfile._Fields.values(); - } - - /** - * Returns the {@code <T>} implementation class associated with this serializer. - * - * @return The {@code <T>} implementation class - */ - @Override - protected Class<UserProfile> getThriftClass() { - return null; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-core/src/test/java/org/apache/airavata/userprofile/core/UserProfileCPIImplTest.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-core/src/test/java/org/apache/airavata/userprofile/core/UserProfileCPIImplTest.java b/modules/user-profile/user-profile-core/src/test/java/org/apache/airavata/userprofile/core/UserProfileCPIImplTest.java deleted file mode 100644 index 737aa6b..0000000 --- a/modules/user-profile/user-profile-core/src/test/java/org/apache/airavata/userprofile/core/UserProfileCPIImplTest.java +++ /dev/null @@ -1,68 +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.userprofile.core; - -import junit.framework.Assert; -import org.apache.airavata.model.user.Status; -import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.userprofile.cpi.UserProfileException; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class UserProfileCPIImplTest { - private final static Logger logger = LoggerFactory.getLogger(UserProfileCPIImplTest.class); - - /* @Test - public void testUserProfileCPIImplementation(){ - UserProfile userProfile = new UserProfile(); - userProfile.setUserName("jsfsjdfsdg" + System.currentTimeMillis()); - userProfile.setGatewayId("seagrid"); - userProfile.setComments("vidfkj dfgndfkg dfkgndkjfng"); - userProfile.setCountry("USA"); - userProfile.setState(Status.ACTIVE); - - try { - UserProfileCPIImpl userProfileCPIImpl = new UserProfileCPIImpl(); - String userId = userProfileCPIImpl.createUserProfile(userProfile); - Assert.assertNotNull(userId); - userProfile = userProfileCPIImpl.getUserProfileFromUserId(userId); - Assert.assertNotNull(userProfile); - Assert.assertTrue(userProfile.getCountry().equals("USA")); - userProfile.setCountry("Sri Lanka"); - userProfileCPIImpl.updateUserProfile(userProfile); - userProfile = userProfileCPIImpl.getUserProfileFromUserId(userId); - Assert.assertTrue(userProfile.getCountry().equals("Sri Lanka")); - userProfile = userProfileCPIImpl.getUserProfileFromUserName(userProfile.getUserName(), - userProfile.getGatewayId()); - Assert.assertNotNull(userProfile); - List<UserProfile> userProfileList = userProfileCPIImpl.getAllUserProfilesInGateway("seagrid"); - Assert.assertNotNull(userProfileList); - userProfileCPIImpl.deleteUserProfile(userProfile.getUserId()); - Assert.assertNull(userProfileCPIImpl.getUserProfileFromUserId(userProfile.getUserId())); - } catch (UserProfileException e) { - e.printStackTrace(); - Assert.fail(); - } - }*/ -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-cpi/pom.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-cpi/pom.xml b/modules/user-profile/user-profile-cpi/pom.xml deleted file mode 100644 index 440726a..0000000 --- a/modules/user-profile/user-profile-cpi/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--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. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>user-profile</artifactId> - <groupId>org.apache.airavata</groupId> - <version>0.17-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>user-profile-cpi</artifactId> - - - <dependencies> - <dependency> - <groupId>org.apache.airavata</groupId> - <artifactId>airavata-data-models</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileCPI.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileCPI.java b/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileCPI.java deleted file mode 100644 index 76b5e39..0000000 --- a/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileCPI.java +++ /dev/null @@ -1,42 +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.userprofile.cpi; - -import org.apache.airavata.model.user.UserProfile; - -import java.util.List; - -public interface UserProfileCPI { - - public List<UserProfile> getAllUserProfilesInGateway(String gatewayId) throws UserProfileException; - - public String createUserProfile(UserProfile userProfile) throws UserProfileException; - - public boolean updateUserProfile(UserProfile userProfile) throws UserProfileException; - - public boolean deleteUserProfile(String userId) throws UserProfileException; - - public UserProfile getUserProfileFromUserId(String userId) throws UserProfileException; - - public UserProfile getUserProfileFromUserName(String userName, String gatewayId) throws UserProfileException; - - public boolean userProfileExists(String userName, String gatewayId) throws UserProfileException; -} http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileException.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileException.java b/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileException.java deleted file mode 100644 index 645210b..0000000 --- a/modules/user-profile/user-profile-cpi/src/main/java/org/apache/airavata/userprofile/cpi/UserProfileException.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.userprofile.cpi; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UserProfileException extends Exception { - private final static Logger logger = LoggerFactory.getLogger(UserProfileException.class); - - public UserProfileException(Exception e) { - super(e); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-service/.classpath ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/.classpath b/modules/user-profile/user-profile-service/.classpath new file mode 100644 index 0000000..af1430b --- /dev/null +++ b/modules/user-profile/user-profile-service/.classpath @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="target/classes"/> +</classpath> http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/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 new file mode 100644 index 0000000..3e35699 --- /dev/null +++ b/modules/user-profile/user-profile-service/pom.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.airavata</groupId> + <artifactId>user-profile-service</artifactId> + <version>0.17-SNAPSHOT</version> + + <dependencies> + + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-commons</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>user-profile-stubs</artifactId> + <version>${project.version}</version> + </dependency> + + </dependencies> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java b/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java new file mode 100644 index 0000000..f07426c --- /dev/null +++ b/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileHandler.java @@ -0,0 +1,85 @@ +package com.apache.airavata.user.profile.server; + +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.registry.api.exception.RegistryServiceException; +import org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity; +import org.apache.airavata.registry.core.repositories.workspacecatalog.UserProfileRepository; +import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; +import org.apache.thrift.TException; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by Airavata on 11/11/2016. + */ +public class UserProfileHandler implements UserProfileCrudeService.Iface { + + private UserProfileRepository userProfileRepository; + + public UserProfileHandler() { + + userProfileRepository = new UserProfileRepository(UserProfile.class, UserProfileEntity.class); + } + + public String addUserProfile(UserProfile userProfile) throws RegistryServiceException, TException { + + userProfileRepository.create(userProfile); + + if (null != userProfile) + return userProfile.getUserId(); + + return null; + } + + public boolean updateUserProfile(UserProfile userProfile) throws RegistryServiceException, TException { + + try { + userProfileRepository.update(userProfile); + } catch (Exception e) { + + return false; + } + + return true; + } + + public UserProfile getUserProfileById(String userId, String gatewayId) throws RegistryServiceException, TException { + + + UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); + + return userProfile; + } + + public boolean deleteUserProfile(String userId) throws RegistryServiceException, TException { + + boolean deleteResult = userProfileRepository.delete(userId); + + return deleteResult; + } + + + + public List<UserProfile> getAllUserProfilesInGateway(String gatewayId, int offset, int limit) throws RegistryServiceException, TException { + List<UserProfile> usersInGateway = userProfileRepository.getAllUserProfilesInGateway(gatewayId, offset, limit); + return usersInGateway; + } + + + public UserProfile getUserProfileByName(String userName, String gatewayId) throws RegistryServiceException, TException { + + UserProfile userProfile = userProfileRepository.getUserProfileByNameAndGateWay(userName, gatewayId); + return userProfile; + } + + public boolean doesUserExist(String userName, String gatewayId) throws RegistryServiceException, TException { + + UserProfile userProfile = userProfileRepository.getUserProfileByNameAndGateWay(userName, gatewayId); + + if (null != userProfile) + return true; + return false; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java b/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java new file mode 100644 index 0000000..53fd539 --- /dev/null +++ b/modules/user-profile/user-profile-service/src/main/java/com.apache.airavata.user.profile/server/UserProfileServer.java @@ -0,0 +1,141 @@ +package com.apache.airavata.user.profile.server; + +import org.apache.airavata.common.utils.IServer; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TThreadPoolServer; +import org.apache.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TServerTransport; +import org.apache.thrift.transport.TTransportException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetSocketAddress; +import java.util.Date; + +/** + * Created by abhij on 11/11/2016. + */ +public class UserProfileServer implements IServer { + + private final static Logger logger = LoggerFactory.getLogger(UserProfileServer.class); + + private static final String SERVER_NAME = "User Profile Server"; + private static final String SERVER_VERSION = "1.0"; + + private IServer.ServerStatus status; + private TServer server; + + public UserProfileServer() { + setStatus(IServer.ServerStatus.STOPPED); + } + + public void updateTime() { + + } + + public Date getTime() { + return null; + } + + public String getName() { + return SERVER_NAME; + } + + public String getVersion() { + return SERVER_VERSION; + } + + public void start() throws Exception { + + + try { + setStatus(ServerStatus.STARTING); + final int serverPort = Integer.parseInt(ServerSettings.getUserProfileServerPort()); + final String serverHost = ServerSettings.getUserProfileServerHost(); + UserProfileCrudeService.Processor processor = new UserProfileCrudeService.Processor(new UserProfileHandler()); + + TServerTransport serverTransport; + + if (serverHost == null) { + serverTransport = new TServerSocket(serverPort); + } else { + InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort); + serverTransport = new TServerSocket(inetSocketAddress); + } + TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport); + options.minWorkerThreads = 30; + server = new TThreadPoolServer(options.processor(processor)); + + new Thread() { + public void run() { + server.serve(); + setStatus(ServerStatus.STOPPED); + logger.info("User Profile Server Stopped."); + } + }.start(); + new Thread() { + public void run() { + while (!server.isServing()) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + break; + } + } + if (server.isServing()) { + setStatus(ServerStatus.STARTED); + logger.info("Starting User Profile Server on Port " + serverPort); + logger.info("Listening to User Profile server clients ...."); + } + } + }.start(); + } catch (TTransportException e) { + setStatus(ServerStatus.FAILED); + throw new Exception("Error while starting the User Profile service", e); + } + } + + public void stop() throws Exception { + + if (server!=null && server.isServing()){ + setStatus(ServerStatus.STOPING); + server.stop(); + } + } + + public void restart() throws Exception { + + stop(); + start(); + } + + public void configure() throws Exception { + + } + + public ServerStatus getStatus() throws Exception { + return status; } + + private void setStatus(IServer.ServerStatus stat){ + status=stat; + status.updateTime(); + } + + public TServer getServer() { + return server; + } + + public void setServer(TServer server) { + this.server = server; + } + + public static void main(String[] args) { + try { + new UserProfileServer().start(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-stubs/pom.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-stubs/pom.xml b/modules/user-profile/user-profile-stubs/pom.xml new file mode 100644 index 0000000..3f9bce8 --- /dev/null +++ b/modules/user-profile/user-profile-stubs/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--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. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>user-profile</artifactId> + <groupId>org.apache.airavata</groupId> + <version>0.17-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>user-profile-stubs</artifactId> + + + <dependencies> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-data-models</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>registry-refactoring</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java new file mode 100644 index 0000000..154ea74 --- /dev/null +++ b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/registry/api/exception/RegistryServiceException.java @@ -0,0 +1,407 @@ + /* + * 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. + */ +/** + * Autogenerated by Thrift Compiler (0.9.3) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.apache.airavata.registry.api.exception; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-11-18") +public class RegistryServiceException extends TException implements org.apache.thrift.TBase<RegistryServiceException, RegistryServiceException._Fields>, java.io.Serializable, Cloneable, Comparable<RegistryServiceException> { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RegistryServiceException"); + + private static final org.apache.thrift.protocol.TField MESSAGE_FIELD_DESC = new org.apache.thrift.protocol.TField("message", org.apache.thrift.protocol.TType.STRING, (short)1); + + private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new RegistryServiceExceptionStandardSchemeFactory()); + schemes.put(TupleScheme.class, new RegistryServiceExceptionTupleSchemeFactory()); + } + + public String message; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + MESSAGE((short)1, "message"); + + private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // MESSAGE + return MESSAGE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.MESSAGE, new org.apache.thrift.meta_data.FieldMetaData("message", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(RegistryServiceException.class, metaDataMap); + } + + public RegistryServiceException() { + } + + public RegistryServiceException( + String message) + { + this(); + this.message = message; + } + + /** + * Performs a deep copy on <i>other</i>. + */ + public RegistryServiceException(RegistryServiceException other) { + if (other.isSetMessage()) { + this.message = other.message; + } + } + + public RegistryServiceException deepCopy() { + return new RegistryServiceException(this); + } + + @Override + public void clear() { + this.message = null; + } + + public String getMessage() { + return this.message; + } + + public RegistryServiceException setMessage(String message) { + this.message = message; + return this; + } + + public void unsetMessage() { + this.message = null; + } + + /** Returns true if field message is set (has been assigned a value) and false otherwise */ + public boolean isSetMessage() { + return this.message != null; + } + + public void setMessageIsSet(boolean value) { + if (!value) { + this.message = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case MESSAGE: + if (value == null) { + unsetMessage(); + } else { + setMessage((String)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case MESSAGE: + return getMessage(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case MESSAGE: + return isSetMessage(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof RegistryServiceException) + return this.equals((RegistryServiceException)that); + return false; + } + + public boolean equals(RegistryServiceException that) { + if (that == null) + return false; + + boolean this_present_message = true && this.isSetMessage(); + boolean that_present_message = true && that.isSetMessage(); + if (this_present_message || that_present_message) { + if (!(this_present_message && that_present_message)) + return false; + if (!this.message.equals(that.message)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List<Object> list = new ArrayList<Object>(); + + boolean present_message = true && (isSetMessage()); + list.add(present_message); + if (present_message) + list.add(message); + + return list.hashCode(); + } + + @Override + public int compareTo(RegistryServiceException other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetMessage()).compareTo(other.isSetMessage()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetMessage()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.message, other.message); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("RegistryServiceException("); + boolean first = true; + + sb.append("message:"); + if (this.message == null) { + sb.append("null"); + } else { + sb.append(this.message); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (message == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'message' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class RegistryServiceExceptionStandardSchemeFactory implements SchemeFactory { + public RegistryServiceExceptionStandardScheme getScheme() { + return new RegistryServiceExceptionStandardScheme(); + } + } + + private static class RegistryServiceExceptionStandardScheme extends StandardScheme<RegistryServiceException> { + + public void read(org.apache.thrift.protocol.TProtocol iprot, RegistryServiceException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // MESSAGE + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.message = iprot.readString(); + struct.setMessageIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, RegistryServiceException struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.message != null) { + oprot.writeFieldBegin(MESSAGE_FIELD_DESC); + oprot.writeString(struct.message); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class RegistryServiceExceptionTupleSchemeFactory implements SchemeFactory { + public RegistryServiceExceptionTupleScheme getScheme() { + return new RegistryServiceExceptionTupleScheme(); + } + } + + private static class RegistryServiceExceptionTupleScheme extends TupleScheme<RegistryServiceException> { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, RegistryServiceException struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + oprot.writeString(struct.message); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, RegistryServiceException struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + struct.message = iprot.readString(); + struct.setMessageIsSet(true); + } + } + +} + http://git-wip-us.apache.org/repos/asf/airavata/blob/d9a69ae5/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java ---------------------------------------------------------------------- diff --git a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java new file mode 100644 index 0000000..9914906 --- /dev/null +++ b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/crude/cpi/Test.java @@ -0,0 +1,14 @@ +package org.apache.airavata.userprofile.crude.cpi; + +import org.apache.airavata.model.user.UserProfile; + +/** + * Created by abhij on 11/17/2016. + */ +public class Test { + + public static void main(String args[]) { + + System.out.println(); + } +}
