
org.kie.uberfire.social.activities.server.SocialUserService Maven / Gradle / Ivy
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* 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.kie.uberfire.social.activities.server;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.inject.Named;
import org.jboss.errai.bus.server.annotations.Service;
import org.kie.uberfire.social.activities.events.SocialUserFollowedEvent;
import org.kie.uberfire.social.activities.events.SocialUserUnFollowedEvent;
import org.kie.uberfire.social.activities.model.SocialUser;
import org.kie.uberfire.social.activities.service.SocialUserPersistenceAPI;
import org.kie.uberfire.social.activities.service.SocialUserServiceAPI;
@Service
@ApplicationScoped
public class SocialUserService implements SocialUserServiceAPI {
@Inject
private Event followedEvent;
@Inject
private Event unFollowedEvent;
@Inject
@Named("socialUserPersistenceAPI")
private SocialUserPersistenceAPI socialUserPersistenceAPI;
@Override
public void userFollowAnotherUser( String followerUsername,
String followUsername ) {
SocialUser follower = socialUserPersistenceAPI.getSocialUser( followerUsername );
SocialUser follow = socialUserPersistenceAPI.getSocialUser( followUsername );
follower.follow( follow );
socialUserPersistenceAPI.updateUsers( follower, follow );
followedEvent.fire( new SocialUserFollowedEvent( follower, follow ) );
}
@Override
public void userUnfollowAnotherUser( String followerUsername,
String followUsername ) {
SocialUser follower = socialUserPersistenceAPI.getSocialUser( followerUsername );
SocialUser user = socialUserPersistenceAPI.getSocialUser( followUsername );
follower.unfollow( user );
socialUserPersistenceAPI.updateUsers( follower, user );
unFollowedEvent.fire( new SocialUserUnFollowedEvent( follower, user ) );
}
@Override
public void update( SocialUser... users) {
socialUserPersistenceAPI.updateUsers( users );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy