protected RepositoryPathMapping convert( CPathMappingItem item ) throws IllegalArgumentException { MappingType type = null; if ( CPathMappingItem.BLOCKING_RULE_TYPE.equals( item.getRouteType() ) ) { type = MappingType.BLOCKING; } else if ( CPathMappingItem.INCLUSION_RULE_TYPE.equals( item.getRouteType() ) ) { type = MappingType.INCLUSION; } else if ( CPathMappingItem.EXCLUSION_RULE_TYPE.equals( item.getRouteType() ) ) { type = MappingType.EXCLUSION; } else { logger.warn( "Unknown route type: " + item.getRouteType() ); throw new IllegalArgumentException( "Unknown route type: " + item.getRouteType() ); } return new RepositoryPathMapping( item.getId(), type, item.getGroupId(), item.getRoutePatterns(), item.getRepositories() ); }
/** * Method upgradeCPathMappingItem. * * @param cPathMappingItem * @return CPathMappingItem */ public org.sonatype.nexus.configuration.model.CPathMappingItem upgradeCPathMappingItem( org.sonatype.nexus.configuration.model.v2_7_0.CPathMappingItem cPathMappingItem ) { return upgradeCPathMappingItem( cPathMappingItem, new org.sonatype.nexus.configuration.model.CPathMappingItem() ); } //-- org.sonatype.nexus.configuration.model.CPathMappingItem upgradeCPathMappingItem( org.sonatype.nexus.configuration.model.v2_7_0.CPathMappingItem )
if ( StringUtils.isEmpty( item.getId() ) || "0".equals( item.getId() ) || ( context.getExistingPathMappingIds() != null && context.getExistingPathMappingIds().contains( item.getId() ) ) ) item.setId( newId ); response.addValidationWarning( "Fixed wrong route ID from '" + item.getId() + "' to '" + newId + "'" ); if ( StringUtils.isEmpty( item.getGroupId() ) ) item.setGroupId( CPathMappingItem.ALL_GROUPS ); + item.getId() + "'." ); if (item.getRoutePatterns() == null || item.getRoutePatterns().isEmpty()) response.addValidationError( "The Route with ID='" + item.getId() + "' must contain at least one Route Pattern." ); for ( String regexp : item.getRoutePatterns() ) response.addValidationError( "The regexp in Route with ID='" + item.getId() + "' is not valid: " + regexp ); context.getExistingPathMappingIds().add( item.getId() ); if ( !CPathMappingItem.INCLUSION_RULE_TYPE.equals( item.getRouteType() ) && !CPathMappingItem.EXCLUSION_RULE_TYPE.equals( item.getRouteType() ) && !CPathMappingItem.BLOCKING_RULE_TYPE.equals( item.getRouteType() ) )
value.setId( cPathMappingItem.getId() ); value.setGroupId( cPathMappingItem.getGroupId() ); value.setRouteType( cPathMappingItem.getRouteType() ); list.add( v ); value.setRoutePatterns( list ); list.add( v ); value.setRepositories( list );
@Subscribe public void onEvent( final RepositoryRegistryEventRemove evt ) { final String repoId = evt.getRepository().getId(); List<CPathMappingItem> pathMappings = getCurrentConfiguration( true ).getPathMappings(); for ( Iterator<CPathMappingItem> iterator = pathMappings.iterator(); iterator.hasNext(); ) { CPathMappingItem item = iterator.next(); if ( item.getGroupId().equals( repoId ) ) { iterator.remove(); } else { item.removeRepository( repoId ); } } }
/** * Method removeRoutePattern. * * @param string */ public void removeRoutePattern( String string ) { getRoutePatterns().remove( string ); } //-- void removeRoutePattern( String )
/** * Method addRepository. * * @param string */ public void addRepository( String string ) { getRepositories().add( string ); } //-- void addRepository( String )
public boolean removeMapping( String id ) { for ( Iterator<CPathMappingItem> i = getCurrentConfiguration( true ).getPathMappings().iterator(); i.hasNext(); ) { CPathMappingItem mapping = i.next(); if ( mapping.getId().equals( id ) ) { i.remove(); return true; } } return false; }
if ( CPathMappingItem.BLOCKING_RULE_TYPE.equals( item.getRouteType() ) ) else if ( CPathMappingItem.INCLUSION_RULE_TYPE.equals( item.getRouteType() ) ) else if ( CPathMappingItem.EXCLUSION_RULE_TYPE.equals( item.getRouteType() ) ) logger.warn( "Unknown route type: " + item.getRouteType() ); throw new IllegalArgumentException( "Unknown route type: " + item.getRouteType() );
if ( StringUtils.isEmpty( item.getId() ) || "0".equals( item.getId() ) || ( context.getExistingPathMappingIds() != null && context.getExistingPathMappingIds().contains( item.getId() ) ) ) item.setId( newId ); response.addValidationWarning( "Fixed wrong route ID from '" + item.getId() + "' to '" + newId + "'" ); if ( StringUtils.isEmpty( item.getGroupId() ) ) item.setGroupId( CPathMappingItem.ALL_GROUPS ); + item.getId() + "'." ); if ( item.getRoutePatterns() == null || item.getRoutePatterns().isEmpty() ) response.addValidationError( "The Route with ID='" + item.getId() + "' must contain at least one Route Pattern." ); for ( String regexp : (List<String>) item.getRoutePatterns() ) response.addValidationError( "The regexp in Route with ID='" + item.getId() + "' is not valid: " + regexp ); context.getExistingPathMappingIds().add( item.getId() ); if ( !CPathMappingItem.INCLUSION_RULE_TYPE.equals( item.getRouteType() ) && !CPathMappingItem.EXCLUSION_RULE_TYPE.equals( item.getRouteType() )
protected CPathMappingItem convert( RepositoryPathMapping item ) { String routeType = null; if ( MappingType.BLOCKING.equals( item.getMappingType() ) ) { routeType = CPathMappingItem.BLOCKING_RULE_TYPE; } else if ( MappingType.INCLUSION.equals( item.getMappingType() ) ) { routeType = CPathMappingItem.INCLUSION_RULE_TYPE; } else if ( MappingType.EXCLUSION.equals( item.getMappingType() ) ) { routeType = CPathMappingItem.EXCLUSION_RULE_TYPE; } CPathMappingItem result = new CPathMappingItem(); result.setId( item.getId() ); result.setGroupId( item.getGroupId() ); result.setRepositories( item.getMappedRepositories() ); result.setRouteType( routeType ); ArrayList<String> patterns = new ArrayList<String>( item.getPatterns().size() ); for ( Pattern pattern : item.getPatterns() ) { patterns.add( pattern.toString() ); } result.setRoutePatterns( patterns ); return result; }
/** * Method addRoutePattern. * * @param string */ public void addRoutePattern( String string ) { getRoutePatterns().add( string ); } //-- void addRoutePattern( String )
/** * Method removeRepository. * * @param string */ public void removeRepository( String string ) { getRepositories().remove( string ); } //-- void removeRepository( String )
public CPathMappingItem getRoute(String id) throws IOException { List<CPathMappingItem> routes = getNexusConfig().getRepositoryGrouping().getPathMappings(); for (Iterator<CPathMappingItem> iter = routes.iterator(); iter.hasNext(); ) { CPathMappingItem groupsSettingPathMappingItem = iter.next(); if (groupsSettingPathMappingItem.getId().equals(id)) { return groupsSettingPathMappingItem; } } return null; }
public void validateRoutesConfig(RepositoryRouteResource resource) throws IOException { CPathMappingItem cRoute = getTest().getNexusConfigUtil().getRoute(resource.getId()); String msg = "Should be the same route. \n Expected:\n" + new XStream().toXML(resource) + " \n \n Got: \n" + new XStream().toXML(cRoute); Assert.assertEquals(msg, cRoute.getId(), resource.getId()); Assert.assertEquals(msg, cRoute.getGroupId(), resource.getGroupId()); Assert.assertEquals(msg, cRoute.getRoutePatterns(), Collections.singletonList(resource.getPattern())); Assert.assertEquals(msg, cRoute.getRouteType(), resource.getRuleType()); this.validateSameRepoIds(resource.getRepositories(), cRoute.getRepositories()); }
CPathMappingItem cPathMappingItem = new CPathMappingItem(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) cPathMappingItem.setId( getTrimmedValue( parser.nextText() ) ); cPathMappingItem.setGroupId( getTrimmedValue( parser.nextText() ) ); cPathMappingItem.setRouteType( getTrimmedValue( parser.nextText() ) ); cPathMappingItem.setRoutePatterns( routePatterns ); while ( parser.nextTag() == XmlPullParser.START_TAG ) cPathMappingItem.setRepositories( repositories ); while ( parser.nextTag() == XmlPullParser.START_TAG )
if ( cPathMappingItem.getId() != null ) serializer.startTag( NAMESPACE, "id" ).text( cPathMappingItem.getId() ).endTag( NAMESPACE, "id" ); if ( cPathMappingItem.getGroupId() != null ) serializer.startTag( NAMESPACE, "groupId" ).text( cPathMappingItem.getGroupId() ).endTag( NAMESPACE, "groupId" ); if ( cPathMappingItem.getRouteType() != null ) serializer.startTag( NAMESPACE, "routeType" ).text( cPathMappingItem.getRouteType() ).endTag( NAMESPACE, "routeType" ); if ( ( cPathMappingItem.getRoutePatterns() != null ) && ( cPathMappingItem.getRoutePatterns().size() > 0 ) ) for ( Iterator iter = cPathMappingItem.getRoutePatterns().iterator(); iter.hasNext(); ) if ( ( cPathMappingItem.getRepositories() != null ) && ( cPathMappingItem.getRepositories().size() > 0 ) ) for ( Iterator iter = cPathMappingItem.getRepositories().iterator(); iter.hasNext(); )