The main problem is in the if block

    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY)) {
    ...
    }

that appears a few lines below this. This block does not get executed if you're in the portlet's configuration screen because the `portletName` equals `PortletKeys.PORTLET_CONFIGURATION` instead.