/*
* Copyright 2014 JBoss Inc
*
* Licensed 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.guvnor.asset.management.backend.social;
import org.guvnor.structure.repositories.NewBranchEvent;
import org.kie.uberfire.social.activities.model.SocialActivitiesEvent;
import org.kie.uberfire.social.activities.model.SocialEventType;
import org.kie.uberfire.social.activities.model.SocialUser;
import org.kie.uberfire.social.activities.service.SocialAdapter;
import org.kie.uberfire.social.activities.service.SocialCommandTypeFilter;
import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ApplicationScoped
public class NewBranchEventAdapter
implements SocialAdapter<NewBranchEvent> {
@Override
public Class<NewBranchEvent> eventToIntercept() {
return NewBranchEvent.class;
}
@Override
public SocialEventType socialEventType() {
return AssetManagementEventTypes.BRANCH_CREATED;
}
@Override
public boolean shouldInterceptThisEvent(Object event) {
if (event.getClass().getSimpleName().equals(eventToIntercept().getSimpleName())) {
return true;
} else {
return false;
}
}
@Override
public SocialActivitiesEvent toSocial(Object object) {
NewBranchEvent event = (NewBranchEvent) object;
return new SocialActivitiesEvent(
new SocialUser("Mr. Process"),
AssetManagementEventTypes.BRANCH_CREATED.name(),
new Date(event.getTimestamp())
).withAdicionalInfo("Branch " + event.getBranchName() + " created for repository " + event.getRepositoryAlias());
}
@Override
public List<SocialCommandTypeFilter> getTimelineFilters() {
return new ArrayList<SocialCommandTypeFilter>();
}
@Override
public List<String> getTimelineFiltersNames() {
return new ArrayList<String>();
}
}