<commit_before>package uk.ac.ox.oucs.oauth.tool.user.pages;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.sakaiproject.tool.api.SessionManager;
import uk.ac.ox.oucs.oauth.domain.Accessor;
import uk.ac.ox.oucs.oauth.domain.Consumer;
import uk.ac.ox.oucs.oauth.service.OAuthService;
import uk.ac.ox.oucs.oauth.tool.pages.SakaiPage;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;

/**
 * @author <NAME>
 */
public class ListAccessors extends SakaiPage {
    @SpringBean
    private SessionManager sessionManager;
    @SpringBean
    private OAuthService oAuthService;

    public ListAccessors() {
        String userId = sessionManager.getCurrentSessionUserId();
        Collection<Accessor> accessors = oAuthService.getAccessAccessorForUser(userId);
        add(new ListView<Accessor>("accessorlist", new ArrayList<Accessor>(accessors)) {
            @Override
            protected void populateItem(ListItem<Accessor> components) {
                final Consumer consumer = oAuthService.getConsumer(components.getModelObject().getConsumerId());
                DateFormat dateFormat = DateFormat.getDateInstance();
                components.add(new ExternalLink("consumerUrl", consumer.getURL(), consumer.getName()));
                components.add(new Label("consumerDescription", consumer.getDescription()));
                components.add(new Label("creationDate", dateFormat.format(components.getModelObject().getCreationDate())));
                components.add(new Label("expirationDate", dateFormat.format(components.getModelObject().getExpirationDate())));

                components.add(new Link<Accessor>("delete", components.getModel()) {
                    @Override
                    public void onClick() {
                        try {
                            oAuthService.revokeAccessor(getModelObject().getToken());
                            setResponsePage(getPage().getClass());<commit_msg>Disable links in the user tool if the application doesn't have a URL<commit_after>package uk.ac.ox.oucs.oauth.tool.user.pages;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.sakaiproject.tool.api.SessionManager;
import uk.ac.ox.oucs.oauth.domain.Accessor;
import uk.ac.ox.oucs.oauth.domain.Consumer;
import uk.ac.ox.oucs.oauth.service.OAuthService;
import uk.ac.ox.oucs.oauth.tool.pages.SakaiPage;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;

/**
 * @author <NAME>
 */
public class ListAccessors extends SakaiPage {
    @SpringBean
    private SessionManager sessionManager;
    @SpringBean
    private OAuthService oAuthService;

    public ListAccessors() {
        String userId = sessionManager.getCurrentSessionUserId();
        Collection<Accessor> accessors = oAuthService.getAccessAccessorForUser(userId);
        add(new ListView<Accessor>("accessorlist", new ArrayList<Accessor>(accessors)) {
            @Override
            protected void populateItem(ListItem<Accessor> components) {
                final Consumer consumer = oAuthService.getConsumer(components.getModelObject().getConsumerId());
                DateFormat dateFormat = DateFormat.getDateInstance();
                ExternalLink consumerHomepage = new ExternalLink("consumerUrl", consumer.getURL(), consumer.getName());
                consumerHomepage.setEnabled(consumer.getURL() != null && !consumer.getURL().isEmpty());
                components.add(consumerHomepage);
                components.add(new Label("consumerDescription", consumer.getDescription()));
                components.add(new Label("creationDate", dateFormat.format(components.getModelObject().getCreationDate())));
                components.add(new Label("expirationDate", dateFormat.format(components.getModelObject().getExpirationDate())));

                components.add(new Link<Accessor>("delete", components.getModel()) {
                    @Override
                    public void onClick() {
                        try {
                            oAuthService.revokeAccessor(getModelObject().getToken());
                            setResponsePage(getPage().getClass());
{'fraction_non_alphanumeric': 0.11431601272534464, 'fraction_numerical': 0.0, 'mean_word_length': 3.326605504587156, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6024069', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1246, 'n_words': 201}