if (remoteTypeId == null) { final Iterable<EntityLink> entityLinks = Iterables.filter(entityLinkService.getEntityLinksForKey(localKey, localType.getClass()), new Predicate<EntityLink>() { public boolean apply(final EntityLink input) { return input.isPrimary(); } else { final EntityType remoteType = typeAccessor.loadEntityType(remoteTypeId); final EntityLink primary = entityLinkService.getPrimaryEntityLinkForKey(localKey, localType.getClass(), remoteType.getClass()); if (primary != null) { response = ok(new EntityLinkEntity(primary));
final EntityType remoteType = typeAccessor.loadEntityType(remoteTypeId.get()); checkPermissionToManageEntityLink(localKey, localType); final EntityLink entity = entityLinkService.getEntityLink(localKey, localType.getClass(), remoteKey, remoteType.getClass(), applicationId); if (entity == null) { return linkNotFound(localType.getClass(), localKey, remoteType.getClass(), remoteKey, applicationId); if (reciprocate != null && reciprocate) { try { deleteSucceeded = entityLinkService.deleteReciprocatedEntityLink(localKey, localType.getClass(), entity); } catch (CredentialsRequiredException e) { return credentialsRequired(i18nResolver); deleteSucceeded = entityLinkService.deleteEntityLink(localKey, localType.getClass(), entity);
@POST @Path("primary/{type}/{key}") public Response makePrimary(@PathParam("type") final TypeId localTypeId, @PathParam("key") final String localKey, @QueryParam("typeId") final TypeId remoteTypeId, @QueryParam("key") final String remoteKey, @QueryParam("applicationId") final String applicationIdString) { checkParam("type", remoteTypeId); checkParam("key", remoteKey); checkParam("applicationId", applicationIdString); final Response response; final EntityType localType = typeAccessor.loadEntityType(localTypeId.get()); checkPermissionToManageEntityLink(localKey, localType); final EntityType remoteType = typeAccessor.loadEntityType(remoteTypeId.get()); final ApplicationId applicationId = new ApplicationId(applicationIdString); final EntityLink link = entityLinkService.getEntityLink(localKey, localType.getClass(), remoteKey, remoteType.getClass(), applicationId); if (link == null) { response = linkNotFound(localType.getClass(), localKey, remoteType.getClass(), remoteKey, applicationId); } else { response = ok(new EntityLinkEntity(entityLinkService.makePrimary(localKey, localType.getClass(), link))); } return response; }
final EntityLink existingEntityLink = entityLinkService.getEntityLink(localKey, localType.getClass(), entity.getKey(), remoteType.getClass(), entity.getApplicationId()); final EntityLink newLink; if (existingEntityLink != null) { entityLinkService.addReciprocatedEntityLink(localKey, localType.getClass(), newLink); } catch (final CredentialsRequiredException e) { return credentialsRequired(i18nResolver); entityLinkService.addEntityLink(localKey, localType.getClass(), newLink);
@Override public List<Job> getLinked(String projectKey) { final StringBuilder where = new StringBuilder(); for (EntityLink entityLink : entityLinkService.getEntityLinksForKey(projectKey, JiraProjectEntityType.class)) { if (entityLink.getType() instanceof JenkinsJobEntityLinkType || entityLink.getType() instanceof HudsonJobEntityLinkType) { if (where.length() > 0) {
final EntityLink primaryEntityLink = mutatingEntityLinkService.getPrimaryEntityLinkForKey(resourceName, localType.getClass(), remoteEntityTypes.next().getClass());
private void addEntity(final ApplicationLink applicationLink, final String jiraProjectKey, final String entityKey, final String entityName, final EntityType entityType) { entityLinkService.addEntityLink(jiraProjectKey, JiraProjectEntityType.class, entityLinkBuilderFactory.builder() .type(entityType) .key(entityKey) //name of repo is unique for each FE instance .name(entityName) .applicationLink(applicationLink) .primary(false) //TODO: think about how to determine primary-ness of a repo. .build() ); }
final Map<String, List<String>> entityLinkCruMappings = Maps.newHashMap(); for (Project project : projectManager.getProjectObjects()) { final Iterable<EntityLink> entityLinks = entityLinkService.getEntityLinks(project, FishEyeCrucibleProjectEntityType.class); for (EntityLink entityLink : entityLinks) { if (!applinksInstance.getId().equals(entityLink.getApplicationLink().getId()))
@GET @Path("delete-entity/{id}/{localType}/{localKey}/{remoteType}/{remoteKey}") public Response canDeleteEntityLink(@PathParam("id") final ApplicationId applicationId, @PathParam("localType") final TypeId localTypeId, @PathParam("localKey") final String localKey, @PathParam("remoteType") final TypeId remoteTypeId, @PathParam("remoteKey") final String remoteKey) { final PermissionCode canModifyApp = hasPermissionToModify(applicationId); if (canModifyApp != PermissionCode.ALLOWED) { return response(canModifyApp); // if the user can't modify the application link, they can't delete the entity link } final EntityType localType = typeAccessor.loadEntityType(localTypeId); if (localType == null) { return typeNotInstalled(localTypeId); // todo use exception mapper } final EntityType remoteType = typeAccessor.loadEntityType(remoteTypeId); if (remoteType == null) { return typeNotInstalled(remoteTypeId); // todo use exception mapper } if (entityLinkService.getEntityLink(localKey, localType.getClass(), remoteKey, remoteType.getClass(), applicationId) == null) { return response(PermissionCode.MISSING); // no matching entity link for this application } return response(PermissionCode.ALLOWED); }
try { applicationLink = applicationLinkService.getApplicationLink(id); entityCount = Lists.newArrayList(entityLinkService.getEntityLinksForApplicationLink(applicationLink)).size(); } catch (TypeNotInstalledException e) { return notFound(i18nResolver.getText("applinks.type.not.installed", e.getType()));
@GET @Path("primaryLinks/{type}/{key}") public Response getEntityLinks(@PathParam("type") final TypeId localTypeId, @PathParam("key") final String localKey) { final EntityType localType = typeAccessor.loadEntityType(localTypeId.get()); checkPermissionToManageEntityLink(localKey, localType); final Map<String, Set<EntityLinkEntity>> linkMap = new HashMap<String, Set<EntityLinkEntity>>(); for (final EntityLink link : entityLinkService.getEntityLinksForKey(localKey, localType.getClass())) { Set<EntityLinkEntity> links = linkMap.get(link.getType().getI18nKey()); if (links == null) { links = new TreeSet<EntityLinkEntity>(PRIMARY_FIRST); linkMap.put(link.getType().getI18nKey(), links); } links.add(new EntityLinkEntity(link)); } return ok(linkMap); }
final Iterable<EntityLink> entityLinksForProject = entityLinkService.getEntityLinks(project, FishEyeRepositoryEntityType.class); for (final EntityLink entity : entityLinksForProject) { if (!applinksInstance.getId().equals(entity.getApplicationLink().getId()))
/** * @param localTypeId the type of the local application entity to look up links for * @param localKey the key of the local application entity to look up links for * @param remoteTypeId (optional) the type of remote application entities to look up links for * @return a collection of links, optionally of the specified remote application type, associated with the * specified local application entity */ @GET @Path("list/{type}/{key}") public Response getApplicationEntityLinks(@PathParam("type") final TypeId localTypeId, @PathParam("key") final String localKey, @QueryParam("typeId") final TypeId remoteTypeId) { final List<EntityLinkEntity> entities; final EntityType localType = typeAccessor.loadEntityType(localTypeId.get()); checkPermissionToManageEntityLink(localKey, localType); if (remoteTypeId != null) { final EntityType remoteType = typeAccessor.loadEntityType(remoteTypeId.get()); entities = toRestApplicationEntities(entityLinkService.getEntityLinksForKey(localKey, localType.getClass(), remoteType.getClass())); } else { entities = toRestApplicationEntities(entityLinkService.getEntityLinksForKey(localKey, localType.getClass())); } return ok(new RestEntityLinkList(entities)); }
/** * Returns all local entities that have links to entities in the supplied * application link. This is used by the upgrade wizard when it needs to * create a decent description for the reciprocate-entity-links checkbox. * The generated wording contains the internationalised names of the local * entity types. * * @param id the id of a local applink. * @return all {@link EntityReference}s that have entity links to the given applink. */ @GET @Path("localEntitiesWithLinksTo/{applinkId}") public Response getLocalEntitiesWithLinksToApplication(@PathParam("applinkId") final ApplicationId id) { final Set<EntityReference> linkedLocalEntities = new HashSet<EntityReference>(); for (EntityReference ref : internalHostApplication.getLocalEntities()) // correctly returns only the visible ones { for (EntityLink link : entityLinkService.getEntityLinksForKey(ref.getKey(), ref.getType().getClass())) { if (id.equals(link.getApplicationLink().getId())) { linkedLocalEntities.add(ref); } } } return ok(new ReferenceEntityList(linkedLocalEntities)); }
for (final EntityLink entityLink : entityLinkService.getEntityLinksForKey( entityReference.getKey(), entityReference.getType().getClass())) {