@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); }
@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 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);
final EntityLink existingEntityLink = entityLinkService.getEntityLink(localKey, localType.getClass(), entity.getKey(), remoteType.getClass(), entity.getApplicationId()); final EntityLink newLink; if (existingEntityLink != null) {