1 package org.apache.archiva.event;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.event.context.RepositoryContext;
21 import org.apache.archiva.event.context.RestContext;
22 import org.apache.archiva.event.context.UserContext;
25 * Static helper class that allows to set certain context data
27 * @author Martin Schreier <martin_s@apache.org>
29 public class EventContextBuilder
33 public static void setUserContext(Event evt, String user, String remoteAddress) {
34 evt.setContext( UserContext.class, new UserContext( user, remoteAddress ) );
37 public static void setRestcontext(Event evt, String service, String path, String operation, int resultCode, String... parameters ) {
38 evt.setContext( RestContext.class, new RestContext( service, path, operation, resultCode, parameters ) );
41 public static void setRepositoryContext(Event evt, String id, String type, String flavour ) {
42 evt.setContext( RepositoryContext.class, new RepositoryContext( id, type, flavour ) );
45 private EventContextBuilder( Event evt) {
49 public static EventContextBuilder withEvent( Event evt )
51 return new EventContextBuilder( evt );
54 public EventContextBuilder withUser( String user, String remoteAddress) {
55 setUserContext( this.evt, user, remoteAddress );
59 public EventContextBuilder witRest( String service, String path, String operation, int resultCode, String... parameters) {
60 setRestcontext( this.evt, service, path, operation, resultCode, parameters );
64 public EventContextBuilder withRepository(String id, String type, String flavour) {
65 setRepositoryContext( this.evt, id, type, flavour );
69 public Event apply() {