Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.marvelution.jira.plugins.sonar.services.associations.SonarAssociationManagerService Maven / Gradle / Ivy
/*
* Licensed to Marvelution under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Marvelution 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 com.marvelution.jira.plugins.sonar.services.associations;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collection;
import net.java.ao.DBParam;
import net.java.ao.Query;
import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.jira.bc.project.component.ProjectComponent;
import com.atlassian.jira.project.Project;
import com.google.common.collect.Lists;
import com.marvelution.jira.plugins.sonar.services.servers.SonarServer;
import com.marvelution.jira.plugins.sonar.services.servers.SonarServerManager;
/**
* Default {@link SonarAssociationManager} implementation
*
* @author Mark Rekveld
*/
public class SonarAssociationManagerService implements SonarAssociationManager {
private final ActiveObjects objects;
private final SonarServerManager serverManager;
/**
* Constructor
*
* @param objects the {@link ActiveObjects} implementation
* @param serverManager the {@link SonarServerManager} implementation
*/
public SonarAssociationManagerService(ActiveObjects objects, SonarServerManager serverManager) {
this.objects = checkNotNull(objects, "activeObjects");
this.serverManager = checkNotNull(serverManager, "serverManager");
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasAssociation(int associationId) {
return getAssociation(associationId) != null;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasAssociations() {
return objects.count(SonarAssociation.class) > 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasAssociations(Project project) {
return getAssociations(project).size() > 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasAssociations(Project project, ProjectComponent component) {
return getAssociations(project, component).size() > 0;
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation getAssociation(int associationId) {
return objects.get(SonarAssociation.class, associationId);
}
/**
* {@inheritDoc}
*/
@Override
public Collection getAssociations() {
return Lists.newArrayList(objects.find(SonarAssociation.class));
}
/**
* {@inheritDoc}
*/
@Override
public Collection getAssociations(Project project) {
return Lists.newArrayList(objects.find(SonarAssociation.class,
Query.select().where("PROJECT_ID = ?", project.getId())));
}
/**
* {@inheritDoc}
*/
@Override
public Collection getAssociations(Project project, ProjectComponent component) {
if (component == null) {
return getAssociations(project);
}
return Lists.newArrayList(objects.find(SonarAssociation.class,
Query.select().where("PROJECT_ID = ? AND COMPONENT_ID = ?", project.getId(), component.getId())));
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation addAssociation(SonarServer server, long projectId, long componentId, String resourceName) {
checkNotNull(server, "server");
checkNotNull(projectId, "projectId");
checkNotNull(componentId, "componentId");
checkNotNull(resourceName, "resourceName");
SonarAssociation association = objects.create(SonarAssociation.class, new DBParam("PROJECT_ID", projectId),
new DBParam("SONAR_SERVER_ID", server.getID()), new DBParam("SONAR_PROJECT", resourceName));
association.setComponentId(componentId);
association.save();
return association;
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation addAssociation(int serverId, long projectId, long componentId, String resourceName) {
return addAssociation(serverManager.getServer(serverId), projectId, componentId, resourceName);
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation addAssociation(SonarAssociation association) {
return addAssociation(association.getSonarServer(), association.getProjectId(), association.getComponentId(),
association.getSonarProject());
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation updateAssociation(int associationId, SonarServer server, long projectId,
long componentId, String resourceName) {
SonarAssociation association = getAssociation(associationId);
checkNotNull(association, "association");
checkNotNull(server, "server");
checkNotNull(projectId, "projectId");
checkNotNull(componentId, "componentId");
checkNotNull(resourceName, "resourceName");
association.setSonarServer(server);
association.setProjectId(projectId);
association.setComponentId(componentId);
association.setSonarProject(resourceName);
association.save();
return association;
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation updateAssociation(int associationId, int serverId, long projectId, long componentId,
String resourceName) {
return updateAssociation(associationId, serverManager.getServer(serverId), projectId, componentId,
resourceName);
}
/**
* {@inheritDoc}
*/
@Override
public SonarAssociation updateAssociation(SonarAssociation association) {
checkNotNull(association, "association");
association.save();
return association;
}
/**
* {@inheritDoc}
*/
@Override
public void removeAssociation(int associationId) {
SonarAssociation association = getAssociation(associationId);
checkNotNull(association, "No SonarAssociation configured with Id: " + associationId);
removeAssociation(association);
}
/**
* {@inheritDoc}
*/
@Override
public void removeAssociation(SonarAssociation association) {
checkNotNull(association, "association");
objects.delete(association);
}
}