List of usage examples for org.apache.wicket.markup.html.list ListView ListView
public ListView(final String id, final List<T> list)
From source file:com.doculibre.constellio.wicket.panels.admin.credentialGroup.AddEditCredentialGroupPanel.java
License:Open Source License
public AddEditCredentialGroupPanel(String id, CredentialGroup credentialGroup) { super(id, true); this.credentialGroupModel = new EntityModel<CredentialGroup>(credentialGroup); this.isCreation = credentialGroup.getId() == null; Form form = getForm();/*from w w w . jav a2 s. c o m*/ form.setModel(new CompoundPropertyModel(credentialGroupModel)); form.add(new SetFocusBehavior(form)); nameField = new RequiredTextField("name"); nameField.add(new StringValidator.MaximumLengthValidator(255)); connectorInstancesCheckGroup = new CheckGroup("connectorInstances", new PropertyModel(credentialGroupModel, "connectorInstances")); IModel connectorInstancesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = adminCollectionPanel.getCollection(); return new ArrayList<ConnectorInstance>(collection.getConnectorInstances()); } }; connectorInstancesListView = new ListView("connectorInstancesListView", connectorInstancesModel) { @Override protected void populateItem(ListItem item) { ConnectorInstance connectorInstance = (ConnectorInstance) item.getModelObject(); Check check = new Check("check", new ReloadableEntityModel<ConnectorInstance>(connectorInstance)); Label label = new Label("label", connectorInstance.getDisplayName()); item.add(check); item.add(label); } }; connectorInstancesListView.setReuseItems(true); form.add(nameField); form.add(connectorInstancesCheckGroup); connectorInstancesCheckGroup.add(connectorInstancesListView); }
From source file:com.doculibre.constellio.wicket.panels.admin.elevate.ElevateQueryListPanel.java
License:Open Source License
public ElevateQueryListPanel(String id) { super(id);// w w w. ja v a 2s .co m add(new DocIdsPanel("excludedDocIdsPanel", null, false)); IModel elevateQueriesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); String solrCoreName = collection.getName(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); return elevateServices.getQueries(solrCoreName); } }; add(new ListView("queries", elevateQueriesModel) { @Override protected void populateItem(ListItem item) { final String queryText = (String) item.getModelObject(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); final SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); int nbDocs = elevateServices.getElevatedDocIds(querySimpleSearch).size(); item.add(new Label("nbDocs", "" + nbDocs)); final ModalWindow detailsModal = new ModalWindow("detailsModal"); item.add(detailsModal); detailsModal.setInitialHeight(SingleColumnCRUDPanel.MODAL_HEIGHT); detailsModal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); WebMarkupContainer detailsLink = new AjaxLink("detailsLink") { @Override public void onClick(AjaxRequestTarget target) { detailsModal .setContent(new ElevateQueryDocIdsPanel(detailsModal.getContentId(), queryText)); // detailsModal.setTitle(queryText); detailsModal.setWindowClosedCallback(new WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { target.addComponent(ElevateQueryListPanel.this); } }); detailsModal.show(target); } }; item.add(detailsLink); detailsLink.add(new SimpleSearchQueryPanel("queryText", querySimpleSearch)); WebMarkupContainer deleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); elevateServices.deleteQuery(querySimpleSearch); target.addComponent(ElevateQueryListPanel.this); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", ElevateQueryListPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }; item.add(deleteLink); } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.elevate.modal.DocIdsPanel.java
License:Open Source License
public DocIdsPanel(String id, final String queryText, final boolean elevatedDocs) { super(id);// w ww . jav a2 s . c o m docIdsModel = new LoadableDetachableModel() { @Override protected Object load() { List<String> docIds = new ArrayList<String>(); AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); if (elevatedDocs) { SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); docIds = elevateServices.getElevatedDocIds(querySimpleSearch); } else { docIds = elevateServices.getExcludedDocIds(collection); } return docIds; } }; add(new ListView("docIds", docIdsModel) { @Override protected void populateItem(ListItem item) { final String docId = (String) item.getModelObject(); AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); Record record = recordServices.get(docId, collection); if (record == null) { FederationServices federationServices = ConstellioSpringUtils.getFederationServices(); if (collection.isFederationOwner()) { List<RecordCollection> includedCollections = federationServices .listIncludedCollections(collection); for (RecordCollection includedCollection : includedCollections) { record = recordServices.get(docId, includedCollection); if (record != null) { break; } } } if (record == null && collection.isIncludedInFederation()) { List<RecordCollection> ownerCollections = federationServices .listOwnerCollections(collection); for (RecordCollection ownerCollection : ownerCollections) { record = recordServices.get(docId, ownerCollection); if (record != null) { break; } } } } if (record != null) { final RecordModel recordModel = new RecordModel(record); String displayURL = record.getDisplayUrl(); item.add(new Label("docId", displayURL)); WebMarkupContainer deleteLink = new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); Record record = recordModel.getObject(); ElevateServices elevateServices = ConstellioSpringUtils.getElevateServices(); SolrServer solrServer = SolrCoreContext.getSolrServer(collection); try { ConstellioPersistenceUtils.beginTransaction(); if (elevatedDocs) { SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); elevateServices.cancelElevation(record, querySimpleSearch); } else { elevateServices.cancelExclusion(record, collection); } try { solrServer.commit(); } catch (Throwable t) { try { solrServer.rollback(); } catch (Exception e) { throw new RuntimeException(t); } } } finally { ConstellioPersistenceUtils.finishTransaction(false); } Component parent; if (elevatedDocs) { SimpleSearch querySimpleSearch = elevateServices.toSimpleSearch(queryText); boolean empty = elevateServices.getElevatedDocIds(querySimpleSearch).isEmpty(); if (empty) { ModalWindow.closeCurrent(target); parent = null; } else { parent = WicketResourceUtils.findOutputMarkupIdParent(DocIdsPanel.this); } } else { parent = WicketResourceUtils.findOutputMarkupIdParent(DocIdsPanel.this); } if (parent != null) { target.addComponent(parent); } } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", DocIdsPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } @Override public void detachModels() { recordModel.detach(); super.detachModels(); } }; item.add(deleteLink); } else { item.setVisible(false); } } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.facets.values.EditFacetLabelledValuesPanel.java
License:Open Source License
public EditFacetLabelledValuesPanel(String id, CollectionFacet facet) { super(id);/* w w w.j a va2 s. co m*/ this.facetModel = new ReloadableEntityModel<CollectionFacet>(facet); String titleKey = facet.isQueryFacet() ? "queries" : "labelledValues"; IModel titleModel = new StringResourceModel(titleKey, this, null); add(new Label("panelTitle", titleModel)); valuesContainer = new WebMarkupContainer("valuesContainer"); add(valuesContainer); valuesContainer.setOutputMarkupId(true); add(new FilterForm("filterForm")); add(new AddLabelForm("addForm")); final IModel localesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return new ArrayList<Locale>(collection.getLocales()); } }; valuesContainer.add(new ListView("locales", localesModel) { @Override protected void populateItem(ListItem item) { Locale locale = (Locale) item.getModelObject(); item.add(new LocaleNameLabel("localeName", locale, true) { @Override public boolean isVisible() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return collection.getLocales().size() > 1; } }); } }); IModel labelledValuesModel = new LoadableDetachableModel() { @Override protected Object load() { List<String> facetValues; FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); CollectionFacet facet = facetModel.getObject(); if (facet.isFieldFacet()) { facetValues = facetServices.suggestValues(facet, filter); } else { facetValues = new ArrayList<String>(); for (I18NLabel labelledValue : facet.getLabelledValues()) { facetValues.add(labelledValue.getKey()); } } return facetValues; } }; valuesContainer.add(new ListView("items", labelledValuesModel) { @Override protected void populateItem(ListItem item) { final String facetValue = (String) item.getModelObject(); final IModel newFacetValueModel = new Model(facetValue); AjaxEditableLabel editableLabel = new AjaxEditableLabel("value", newFacetValueModel) { @Override protected void onSubmit(AjaxRequestTarget target) { CollectionFacet facet = facetModel.getObject(); String newFacetValue = (String) newFacetValueModel.getObject(); if (newFacetValue == null || !newFacetValue.equals(facetValue)) { FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); for (I18NLabel i18nLabel : facet.getLabelledValues()) { if (i18nLabel.getKey().equals(facetValue)) { if (newFacetValue == null) { EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facet.getLabels().remove(i18nLabel); facetServices.makePersistent(facet); entityManager.getTransaction().commit(); entityManager.clear(); } else { i18nLabel.setKey(newFacetValue); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facetServices.makePersistent(facet); entityManager.getTransaction().commit(); entityManager.clear(); } } } } super.onSubmit(target); } }; item.add(editableLabel); MultiLocaleComponentHolder labelledValuesHolder = new MultiLocaleComponentHolder("labels", facetValue, facetModel, "labelledValue", localesModel) { @Override protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) { AjaxEditableLabel editableLabel = new AjaxEditableLabel("editableLabel", componentModel) { @Override protected void onSubmit(AjaxRequestTarget target) { CollectionFacet facet = facetModel.getObject(); FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } facetServices.makePersistent(facet); entityManager.getTransaction().commit(); entityManager.clear(); super.onSubmit(target); } }; item.add(editableLabel); } }; item.add(labelledValuesHolder); item.add(new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { CollectionFacet facet = facetModel.getObject(); FacetServices facetServices = ConstellioSpringUtils.getFacetServices(); EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } for (Iterator<I18NLabel> it = facet.getLabelledValues().iterator(); it.hasNext();) { I18NLabel labelledValue = it.next(); if (labelledValue.getKey().equals(facetValue)) { it.remove(); } } facetServices.makePersistent(facet); entityManager.getTransaction().commit(); target.addComponent(valuesContainer); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", EditFacetLabelledValuesPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }); } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.indexField.values.EditIndexFieldLabelledValuesPanel.java
License:Open Source License
public EditIndexFieldLabelledValuesPanel(String id, IndexField indexField) { super(id);/*w w w .j a v a 2 s . co m*/ this.indexFieldModel = new ReloadableEntityModel<IndexField>(indexField); String titleKey = "labelledValues"; IModel titleModel = new StringResourceModel(titleKey, this, null); add(new Label("panelTitle", titleModel)); valuesContainer = new WebMarkupContainer("valuesContainer"); add(valuesContainer); valuesContainer.setOutputMarkupId(true); add(new FilterForm("filterForm")); add(new AddLabelForm("addForm")); final IModel localesModel = new LoadableDetachableModel() { @Override protected Object load() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return new ArrayList<Locale>(collection.getLocales()); } }; valuesContainer.add(new ListView("locales", localesModel) { @Override protected void populateItem(ListItem item) { Locale locale = (Locale) item.getModelObject(); item.add(new LocaleNameLabel("localeName", locale, true) { @Override public boolean isVisible() { AdminCollectionPanel collectionAdminPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); RecordCollection collection = collectionAdminPanel.getCollection(); return collection.getLocales().size() > 1; } }); } }); IModel labelledValuesModel = new LoadableDetachableModel() { @Override protected Object load() { IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); IndexField indexField = indexFieldModel.getObject(); List<String> indexFieldValues = indexFieldServices.suggestValues(indexField); for (I18NLabel labelledValue : indexField.getLabelledValues()) { indexFieldValues.add(labelledValue.getKey()); } return indexFieldValues; } }; valuesContainer.add(new ListView("items", labelledValuesModel) { @Override protected void populateItem(ListItem item) { final String indexFieldValue = (String) item.getModelObject(); final IModel newIndexFieldValueModel = new Model(indexFieldValue); AjaxEditableLabel editableLabel = new AjaxEditableLabel("value", newIndexFieldValueModel) { @Override protected void onSubmit(AjaxRequestTarget target) { IndexField indexField = indexFieldModel.getObject(); String newIndexFieldValue = (String) newIndexFieldValueModel.getObject(); if (newIndexFieldValue == null || !newIndexFieldValue.equals(indexFieldValue)) { IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); for (I18NLabel i18nLabel : indexField.getLabelledValues()) { if (i18nLabel.getKey().equals(indexFieldValue)) { if (newIndexFieldValue == null) { EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } indexField.getLabels().remove(i18nLabel); indexFieldServices.makePersistent(indexField, false); entityManager.getTransaction().commit(); entityManager.clear(); } else { i18nLabel.setKey(newIndexFieldValue); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } indexFieldServices.makePersistent(indexField, false); entityManager.getTransaction().commit(); entityManager.clear(); } } } } super.onSubmit(target); } }; item.add(editableLabel); MultiLocaleComponentHolder labelledValuesHolder = new MultiLocaleComponentHolder("labels", indexFieldValue, indexFieldModel, "labelledValue", localesModel) { @Override protected void onPopulateItem(ListItem item, IModel componentModel, Locale locale) { AjaxEditableLabel editableLabel = new AjaxEditableLabel("editableLabel", componentModel) { @Override protected void onSubmit(AjaxRequestTarget target) { IndexField indexField = indexFieldModel.getObject(); IndexFieldServices indexFieldServices = ConstellioSpringUtils .getIndexFieldServices(); EntityManager entityManager = ConstellioPersistenceContext .getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } indexFieldServices.makePersistent(indexField, false); entityManager.getTransaction().commit(); entityManager.clear(); super.onSubmit(target); } }; item.add(editableLabel); } }; item.add(labelledValuesHolder); item.add(new AjaxLink("deleteLink") { @Override public void onClick(AjaxRequestTarget target) { IndexField indexField = indexFieldModel.getObject(); IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } for (Iterator<I18NLabel> it = indexField.getLabelledValues().iterator(); it.hasNext();) { I18NLabel labelledValue = it.next(); if (labelledValue.getKey().equals(indexFieldValue)) { it.remove(); } } indexFieldServices.makePersistent(indexField, false); entityManager.getTransaction().commit(); target.addComponent(valuesContainer); } @Override protected IAjaxCallDecorator getAjaxCallDecorator() { return new AjaxCallDecorator() { @Override public CharSequence decorateScript(CharSequence script) { String confirmMsg = getLocalizer().getString("confirmDelete", EditIndexFieldLabelledValuesPanel.this); return "if (confirm('" + confirmMsg + "')) {" + script + "} else { return false; }"; } }; } }); } }); }
From source file:com.doculibre.constellio.wicket.panels.admin.indexing.AdminIndexingPanel.java
License:Open Source License
public AdminIndexingPanel(String id) { super(id);//from ww w.j a va 2s. c o m sizeDisk = 0; indexedRecords = 0; add(new AjaxSelfUpdatingTimerBehavior(Duration.ONE_SECOND)); // add(new AbstractAjaxTimerBehavior(Duration.ONE_SECOND) { // @Override // protected void onTimer(AjaxRequestTarget target) { // // Do nothing, will prevent page from expiring // } // }); connectorsModel = new LoadableDetachableModel() { @Override protected Object load() { List<ConnectorInstance> connectors; RecordCollection collection = getRecordCollection(); if (collection.isFederationOwner()) { FederationServices federationServices = ConstellioSpringUtils.getFederationServices(); connectors = federationServices.listConnectors(collection); } else { connectors = new ArrayList<ConnectorInstance>(collection.getConnectorInstances()); } return connectors; } }; manageConnectorsLink = new Link("manageConnectorsLink") { @Override public void onClick() { AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); adminCollectionPanel.setSelectedTab(AdminCollectionPanel.CONNECTORS_MANAGEMENT_PANEL); } @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { RecordCollection collection = getRecordCollection(); visible = collection.getConnectorInstances().isEmpty(); } return visible; } }; synchronizeIndexFieldsLink = new Link("synchronizeIndexFieldsLink") { @Override public void onClick() { RecordCollection collection = getRecordCollection(); RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); SolrServices solrServices = ConstellioSpringUtils.getSolrServices(); solrServices.updateSchemaFields(collection); solrServices.initCore(collection); EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } collectionServices.markSynchronized(collection); entityManager.getTransaction().commit(); IndexingManager indexingManager = IndexingManager.get(collection); if (!indexingManager.isActive()) { indexingManager.startIndexing(); } } @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { RecordCollection collection = getRecordCollection(); visible = collection.isSynchronizationRequired(); } return visible; } }; manageIndexFieldsLink = new Link("manageIndexFieldsLink") { @Override public void onClick() { AdminCollectionPanel adminCollectionPanel = (AdminCollectionPanel) findParent( AdminCollectionPanel.class); adminCollectionPanel.setSelectedTab(AdminCollectionPanel.INDEX_FIELDS_MANAGEMENT_PANEL); } }; recordCountLabel = new Label("recordCount", new LoadableDetachableModel() { @Override protected Object load() { RecordCollection collection = getRecordCollection(); return StatusManager.countTraversedRecords(collection); } }); deleteAllLink = new Link("deleteAllLink") { @Override public void onClick() { RecordCollection collection = getRecordCollection(); RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); FederationServices federationServices = ConstellioSpringUtils.getFederationServices(); ReadWriteLock collectionLock = recordServices.getLock(collection.getName()); collectionLock.writeLock().lock(); try { ConstellioPersistenceUtils.beginTransaction(); recordServices.markRecordsForDeletion(collection); if (collection.isFederationOwner()) { List<RecordCollection> includedCollections = federationServices .listIncludedCollections(collection); for (RecordCollection includedCollection : includedCollections) { recordServices.markRecordsForDeletion(includedCollection); } } SolrServer solrServer = SolrCoreContext.getSolrServer(collection); try { solrServer.commit(); solrServer.optimize(); } catch (Throwable t) { try { solrServer.rollback(); } catch (Exception e) { throw new RuntimeException(t); } } } finally { try { ConstellioPersistenceUtils.finishTransaction(false); } finally { collectionLock.writeLock().unlock(); } } // RecordCollection collection = getRecordCollection(); // // ConnectorManagerServices connectorManagerServices = // ConstellioSpringUtils.getConnectorManagerServices(); // ConnectorManager connectorManager = // connectorManagerServices.getDefaultConnectorManager(); // for (ConnectorInstance connectorInstance : // collection.getConnectorInstances()) { // String connectorName = connectorInstance.getName(); // connectorManagerServices.disableConnector(connectorManager, // connectorName); // } // // IndexingManager indexingManager = // IndexingManager.get(collection); // indexingManager.deleteAll(); // indexingManager.optimize(); // while (indexingManager.isOptimizing()) { // try { // Thread.sleep(200); // } catch (InterruptedException e) { // e.printStackTrace(); // } // } } @Override protected CharSequence getOnClickScript(CharSequence url) { String confirmMsg = getLocalizer().getString("confirmDeleteAll", AdminIndexingPanel.this) .replace("'", "\\'"); return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url + "';} else { return false; }"; } }; indexedRecordCountLabel = new Label("indexedRecordCount", new LoadableDetachableModel() { @Override protected Object load() { RecordCollection collection = getRecordCollection(); return StatusManager.countIndexedRecords(collection); } }); controlIndexingButtons = new WebMarkupContainer("controlIndexingButtons"); controlIndexingButtons.setOutputMarkupId(true); reindexAllLink = new Link("reindexAllLink") { @Override public void onClick() { RecordCollection collection = getRecordCollection(); final String collectioName = collection.getName(); final Long collectionId = collection.getId(); new Thread() { @Override public void run() { RecordServices recordServices = ConstellioSpringUtils.getRecordServices(); ReadWriteLock collectionLock = recordServices.getLock(collectioName); collectionLock.writeLock().lock(); try { EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } RecordCollectionServices collectionServices = ConstellioSpringUtils .getRecordCollectionServices(); FederationServices federationServices = ConstellioSpringUtils.getFederationServices(); RecordCollection collection = collectionServices.get(collectionId); try { recordServices.markRecordsForUpdateIndex(collection); if (collection.isFederationOwner()) { List<RecordCollection> includedCollections = federationServices .listIncludedCollections(collection); for (RecordCollection includedCollection : includedCollections) { recordServices.markRecordsForUpdateIndex(includedCollection); } } SolrServer solrServer = SolrCoreContext.getSolrServer(collection); try { // solrServer.commit(); solrServer.optimize(); } catch (Throwable t) { try { solrServer.rollback(); } catch (Exception e) { throw new RuntimeException(t); } } } finally { ConstellioPersistenceUtils.finishTransaction(false); } } finally { collectionLock.writeLock().unlock(); } } }.start(); } @Override protected CharSequence getOnClickScript(CharSequence url) { String confirmMsg = getLocalizer().getString("confirmReindexAll", AdminIndexingPanel.this) .replace("'", "\\'"); return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url + "';} else { return false; }"; } }; resumeIndexingLink = new Link("resumeIndexingLink") { @Override public void onClick() { RecordCollection collection = getRecordCollection(); IndexingManager indexingManager = IndexingManager.get(collection); if (!indexingManager.isActive()) { indexingManager.startIndexing(false); } } @Override public boolean isVisible() { // boolean visible = super.isVisible(); // if (visible) { // RecordCollection collection = getRecordCollection(); // IndexingManager indexingManager = // IndexingManager.get(collection); // visible = !collection.isSynchronizationRequired() && // !indexingManager.isActive(); // } // return visible; return false; } }; optimizeLink = new Link("optimizeLink") { @Override public void onClick() { RecordCollection collection = getRecordCollection(); final Long collectionId = collection.getId(); new Thread() { @Override public void run() { RecordCollectionServices collectionServices = ConstellioSpringUtils .getRecordCollectionServices(); RecordCollection collection = collectionServices.get(collectionId); SolrServer solrServer = SolrCoreContext.getSolrServer(collection); try { solrServer.optimize(); } catch (Throwable t) { try { solrServer.rollback(); } catch (Exception e) { throw new RuntimeException(t); } } // IndexingManager indexingManager = // IndexingManager.get(collection); // if (indexingManager.isActive() && // !indexingManager.isOptimizing()) { // indexingManager.optimize(); // } } }.start(); } @Override protected CharSequence getOnClickScript(CharSequence url) { String confirmMsg = getLocalizer().getString("confirmOptimize", AdminIndexingPanel.this) .replace("'", "\\'"); return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url + "';} else { return false; }"; } @Override public boolean isVisible() { // boolean visible = super.isVisible(); // if (visible) { // RecordCollection collection = getRecordCollection(); // IndexingManager indexingManager = // IndexingManager.get(collection); // visible = indexingManager.isActive(); // } // return visible; return true; } @Override public boolean isEnabled() { // boolean enabled = super.isEnabled(); // if (enabled) { // RecordCollection collection = getRecordCollection(); // IndexingManager indexingManager = // IndexingManager.get(collection); // enabled = indexingManager.isActive() && // !indexingManager.isOptimizing(); // } // return enabled; return true; } }; indexSizeOnDiskLabel = new Label("indexSizeOnDisk", new LoadableDetachableModel() { @Override protected Object load() { RecordCollection collection = getRecordCollection(); return StatusManager.getSizeOnDisk(collection); } }); connectorTraversalStatesListView = new ListView("connectorTraversalStates", connectorsModel) { @Override protected void populateItem(ListItem item) { ConnectorInstance connectorInstance = (ConnectorInstance) item.getModelObject(); final ReloadableEntityModel<ConnectorInstance> connectorInstanceModel = new ReloadableEntityModel<ConnectorInstance>( connectorInstance); Label displayNameLabel = new Label("displayName", connectorInstance.getDisplayName()); Label lastTraversalDateLabel = new Label("latestTraversalDate", new LoadableDetachableModel() { @Override protected Object load() { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); Date lastTraversalDate = StatusManager.getLastTraversalDate(connectorInstance); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return lastTraversalDate != null ? sdf.format(lastTraversalDate) : "---"; } @Override public void detach() { connectorInstanceModel.detach(); super.detach(); } }); Link restartTraversalLink = new Link("restartTraversalLink") { @Override public void onClick() { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils .getConnectorManagerServices(); ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager(); connectorManagerServices.restartTraversal(connectorManager, connectorInstance.getName()); } @Override protected CharSequence getOnClickScript(CharSequence url) { String confirmMsg = getLocalizer() .getString("confirmRestartTraversal", AdminIndexingPanel.this).replace("'", "\\'"); return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url + "';} else { return false; }"; } @Override public boolean isVisible() { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); RecordCollection connectorInstanceCollection = connectorInstance.getRecordCollection(); ConstellioUser user = ConstellioSession.get().getUser(); return super.isVisible() && user.hasAdminPermission(connectorInstanceCollection); } }; Link disableConnectorLink = new Link("disableConnectorLink") { @Override public void onClick() { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); String connectorName = connectorInstance.getName(); ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils .getConnectorManagerServices(); ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager(); connectorManagerServices.disableConnector(connectorManager, connectorName); } @Override protected CharSequence getOnClickScript(CharSequence url) { String confirmMsg = getLocalizer() .getString("confirmDisableConnector", AdminIndexingPanel.this).replace("'", "\\'"); return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url + "';} else { return false; }"; } @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); String connectorName = connectorInstance.getName(); ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils .getConnectorManagerServices(); ConnectorManager connectorManager = connectorManagerServices .getDefaultConnectorManager(); visible = connectorManagerServices.isConnectorEnabled(connectorManager, connectorName); if (visible) { RecordCollection connectorInstanceCollection = connectorInstance .getRecordCollection(); ConstellioUser user = ConstellioSession.get().getUser(); visible = user.hasAdminPermission(connectorInstanceCollection); } } return visible; } }; Link enableConnectorLink = new Link("enableConnectorLink") { @Override public void onClick() { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); String connectorName = connectorInstance.getName(); ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils .getConnectorManagerServices(); ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager(); connectorManagerServices.enableConnector(connectorManager, connectorName); } @Override protected CharSequence getOnClickScript(CharSequence url) { String confirmMsg = getLocalizer() .getString("confirmEnableConnector", AdminIndexingPanel.this).replace("'", "\\'"); return "if (confirm('" + confirmMsg + "')) { window.location.href='" + url + "';} else { return false; }"; } @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); String connectorName = connectorInstance.getName(); ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils .getConnectorManagerServices(); ConnectorManager connectorManager = connectorManagerServices .getDefaultConnectorManager(); visible = !connectorManagerServices.isConnectorEnabled(connectorManager, connectorName); if (visible) { RecordCollection connectorInstanceCollection = connectorInstance .getRecordCollection(); ConstellioUser user = ConstellioSession.get().getUser(); visible = user.hasAdminPermission(connectorInstanceCollection); } } return visible; } }; item.add(displayNameLabel); item.add(lastTraversalDateLabel); item.add(restartTraversalLink); item.add(disableConnectorLink); item.add(enableConnectorLink); } }; latestIndexedRecordsTextArea = new LoggingTextArea("latestIndexedRecordsTextArea", new LoadableDetachableModel() { @Override protected Object load() { RecordCollection collection = getRecordCollection(); return StatusManager.listLastIndexedRecords(collection); } }, refreshTimeMillis); connectorTraversalTextAreasListView = new ListView("connectorTraversalTextAreas", connectorsModel) { @Override protected void populateItem(ListItem item) { ConnectorInstance connectorInstance = (ConnectorInstance) item.getModelObject(); final ReloadableEntityModel<ConnectorInstance> connectorInstanceModel = new ReloadableEntityModel<ConnectorInstance>( connectorInstance); Label displayNameLabel = new Label("displayName", connectorInstance.getDisplayName()); LoggingTextArea traversalTextArea = new LoggingTextArea("traversalTextArea", new LoadableDetachableModel() { @Override protected Object load() { ConnectorInstance connectorInstance = connectorInstanceModel.getObject(); return StatusManager.listLastTraversedRecords(connectorInstance); } }, refreshTimeMillis) { @Override public void detachModels() { connectorInstanceModel.detach(); super.detachModels(); } }; item.add(displayNameLabel); item.add(traversalTextArea); } }; // connectorTextAreasListView.setReuseItems(true); add(manageConnectorsLink); add(synchronizeIndexFieldsLink); add(manageIndexFieldsLink); add(recordCountLabel); add(deleteAllLink); add(indexedRecordCountLabel); add(controlIndexingButtons); controlIndexingButtons.add(reindexAllLink); controlIndexingButtons.add(resumeIndexingLink); controlIndexingButtons.add(optimizeLink); add(indexSizeOnDiskLabel); add(connectorTraversalStatesListView); add(latestIndexedRecordsTextArea); add(connectorTraversalTextAreasListView); /* * Quotas Part of the code : * antoine.timonnier@gmail.com */ //Loading the size of the disk IModel model1 = new LoadableDetachableModel() { protected Object load() { return getsizeDisk(); } }; //Loading the number of documents indexed IModel model2 = new LoadableDetachableModel() { protected Object load() { return getindexedRecords(); } }; //Boolean that is true if both of the quotas are reached boolean bothQuotas = false; QuotasManagerImpl quotasManager = new QuotasManagerImpl(); //TODO connect quotas manager with the quotas.properties /*double quotaSizeDisk = quotasManager.getQuotaSizeDisk(); double quotaIndexedRecords = quotasManager.getQuotaIndexedRecords(); double quotaPercentage = quotasManager.getQuotaPercentage();*/ double quotaSizeDisk = 1; double quotaIndexedRecords = 1; double quotaPercentage = 70; double percentageSizeDisk = (sizeDisk * 100) / quotaSizeDisk; double percentageIndexedRecords = (indexedRecords * 100) / quotaIndexedRecords; //if the size of the disk is upper the quota percentage and doesn't reach the quota (lower than 100%) if (quotaPercentage < percentageSizeDisk && percentageSizeDisk < 100) { final String textPercentageSizeDisk = "Vous tes rendu " + Double.toString(percentageSizeDisk) + "% de votre quota d'espace disque, veuillez contacter un administrateur !"; configurePopUp(popUpPercentageSizeDisk, textPercentageSizeDisk, "Attention"); } add(popUpPercentageSizeDisk); //if the number of doc indexed is upper the quota percentage and doesn't reach the quota (lower than 100%) if (quotaIndexedRecords < percentageIndexedRecords && percentageIndexedRecords < 100) { final String textPercentageIndexedRecords = "Vous tes rendu " + Double.toString(percentageSizeDisk) + "% de votre quota de nombre de documents indexs, veuillez contacter un administrateur !"; configurePopUp(popUpPercentageIndexedRecords, textPercentageIndexedRecords, "Attention"); } add(popUpPercentageIndexedRecords); //Adding a pop up if both of the quotas are reached popUpBothQuotas = new ModalWindow("popUpBothQuotas"); if (sizeDisk > quotaSizeDisk && indexedRecords > quotaIndexedRecords) { bothQuotas = true; // Sending the email // TODO sendEmail(String hostName, int smtpPort, // DefaultAuthenticator authenticator, String sender, String // subject, String message, String receiver); // TODO lock the indexing //Configuration of the popUp final String textBothQuotas = "Vous avez dpass votre quota d'espace disque et votre quotat de document indexs, veuillez contacter un administrateur"; configurePopUp(popUpBothQuotas, textBothQuotas, "Attention"); } add(popUpBothQuotas); //Adding a pop up if the size disk quota is reached popUpSizeDisk = new ModalWindow("popUpSizeDisk"); boolean sizeDiskSuperior = sizeDisk > quotaSizeDisk; if (sizeDiskSuperior && bothQuotas == false) { /* Sending the email try { sendEmail("smtp.googlemail.com", 465, new DefaultAuthenticator("antoine.timonnier@gmail.com","quenellede300"), "antoine.timonnier@gmail.com", "constellio", "blabla", "antoine.timonnier@gmail.com"); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ // TODO lock // Configuration of the popup final String textSizeDisk = "Attention, vous avez dpass votre quota d'espace disque, veuillez contacter un administrateur"; configurePopUp(popUpSizeDisk, textSizeDisk, "Attention"); } add(popUpSizeDisk); //Adding a pop up if the indexed records quota is reached popUpIndexedRecords = new ModalWindow("popUpIndexedRecords"); if (indexedRecords > quotaIndexedRecords && bothQuotas == false) { // sending the email // TODO sendEmail(String hostName, int smtpPort, // DefaultAuthenticator authenticator, String sender, String // subject, String message, String receiver); // TODO lock // Configuration of the popup final String textIndexedRecords = "Attention, vous avez dpass votre quota de documents indexs, veuillez contacter un administrateur. boolean both = " + bothQuotas; configurePopUp(popUpIndexedRecords, textIndexedRecords, "Attention"); } add(popUpIndexedRecords); }
From source file:com.doculibre.constellio.wicket.panels.admin.resultPanels.ConnectorResultClassesPanel.java
License:Open Source License
public ConnectorResultClassesPanel(String id) { super(id);/* w ww. j a v a 2 s. c o m*/ IModel collectionsModel = new LoadableDetachableModel() { @Override protected Object load() { return ConstellioSpringUtils.getRecordCollectionServices().list(); } }; ListView collections = new ListView("collections", collectionsModel) { @Override protected void populateItem(ListItem item) { RecordCollection collection = (RecordCollection) item.getModelObject(); Locale displayLocale = collection.getDisplayLocale(getLocale()); String collectionTitle = collection.getTitle(displayLocale); item.add(new Label("name", collectionTitle)); item.add(new ConnectorResultClassesListPanel("connectors", collection)); } }; add(collections); }
From source file:com.doculibre.constellio.wicket.panels.admin.searchInterface.generalOptions.advancedSearch.AdvancedSearchOptionsListPanel.java
License:Open Source License
public AdvancedSearchOptionsListPanel(String id) { super(id);// ww w .j a v a 2 s. co m IModel collectionsModel = new LoadableDetachableModel() { @Override protected Object load() { return ConstellioSpringUtils.getRecordCollectionServices().list(); } }; ListView collections = new ListView("collections", collectionsModel) { @Override protected void populateItem(final ListItem item) { RecordCollection collection = (RecordCollection) item.getModelObject(); Locale displayLocale = collection.getDisplayLocale(getLocale()); String collectionTitle = collection.getTitle(displayLocale); FoldableSectionPanel section = new FoldableSectionPanel("foldableSection", new Model(collectionTitle)) { @Override protected Component newFoldableSection(String id) { return new AdvancedSearchOptionsPanel(id, item.getModel()); } }; section.setOpened(false); item.add(section); } }; add(collections); }
From source file:com.doculibre.constellio.wicket.panels.admin.searchInterface.generalOptions.advancedSearch.AdvancedSearchOptionsPanel.java
License:Open Source License
private ListView getEnabledRulesListView() { AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices(); final List<String> autoCompleteSupportedFields = new ArrayList<String>(); for (IndexField indexField : autocompleteServices.getAutoCompleteIndexFields(collectionModel.getObject())) { autoCompleteSupportedFields.add(indexField.getName()); }//from w ww .ja v a 2s .c o m // IModel indexFieldsModel = new LoadableDetachableModel() { // // @Override // protected Object load() { // RecordCollection collection = collectionModel.getObject(); // List<IndexField> indexFields = new ArrayList<IndexField>(); // indexFields.addAll(collection.getIndexFields()); // Collections.sort(indexFields, new Comparator<IndexField>() { // // @Override // public int compare(IndexField o1, IndexField o2) { // return o1.getName().toLowerCase() // .compareTo(o2.getName().toLowerCase()); // } // }); // return indexFields; // } // }; IModel indexFieldsModel = new CollectionIndexFieldsModel(collectionModel); ListView enabledRules = new ListView("enabledRules", indexFieldsModel) { @Override protected void populateItem(ListItem item) { IndexField indexField = (IndexField) item.getModelObject(); final String indexFieldName = indexField.getName(); AdvancedSearchEnabledRule rule = null; for (AdvancedSearchEnabledRule ruleIt : collectionModel.getObject() .getAdvancedSearchEnabledRules()) { if (ruleIt.getIndexField().equals(indexField)) { rule = ruleIt; break; } } final boolean enabled = rule != null; item.add(new Label("indexFieldName", indexFieldName)); AjaxCheckBox enabledCheckBox = new AjaxCheckBox("enabled", new Model(enabled)) { @Override protected void onUpdate(AjaxRequestTarget target) { EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } RecordCollection collection = collectionModel.getObject(); AdvancedSearchEnabledRule rule = null; for (AdvancedSearchEnabledRule ruleIt : collection.getAdvancedSearchEnabledRules()) { if (ruleIt.getIndexField().getName().equals(indexFieldName)) { rule = ruleIt; break; } } if (rule == null) { AdvancedSearchEnabledRule enabledRule = new AdvancedSearchEnabledRule(); enabledRule.setIndexField(collection.getIndexField(indexFieldName)); enabledRule.setRecordCollection(collection); collection.getAdvancedSearchEnabledRules().add(enabledRule); } else { collection.getAdvancedSearchEnabledRules().remove(rule); } RecordCollectionServices recordCollectionServices = ConstellioSpringUtils .getRecordCollectionServices(); recordCollectionServices.merge(collection); entityManager.getTransaction().commit(); target.addComponent(AdvancedSearchOptionsPanel.this); } }; item.add(enabledCheckBox); AjaxCheckBox autocompleteCheckBox = new AjaxCheckBox("autocomplete", new Model(indexField.isAutocompleted())) { @Override protected void onUpdate(AjaxRequestTarget target) { RecordCollection collection = collectionModel.getObject(); if (indexFieldName != null) { EntityManager entityManager = ConstellioPersistenceContext.getCurrentEntityManager(); if (!entityManager.getTransaction().isActive()) { entityManager.getTransaction().begin(); } IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices(); AutocompleteServices autocompleteServices = ConstellioSpringUtils .getAutocompleteServices(); IndexField indexField = indexFieldServices.get(indexFieldName, collection); if (indexField.isAutocompleted()) { autocompleteServices.removeAutoCompleteFromField(indexField); } else { autocompleteServices.setAutoCompleteToField(indexField); } // RecordCollectionServices recordCollectionServices = ConstellioSpringUtils // .getRecordCollectionServices(); // recordCollectionServices.makePersistent(indexField.getRecordCollection(), true); indexFieldServices.makePersistent(indexField, true); entityManager.getTransaction().commit(); } target.addComponent(AdvancedSearchOptionsPanel.this); } }; autocompleteCheckBox.setEnabled(enabled); item.add(autocompleteCheckBox); } @Override public boolean isVisible() { RecordCollection collection = collectionModel.getObject(); return collection.isAdvancedSearchEnabled(); } }; return enabledRules; }
From source file:com.doculibre.constellio.wicket.panels.admin.searchResultField.AdminSearchResultFieldsPanel.java
License:Open Source License
public AdminSearchResultFieldsPanel(String id) { super(id);/*from w ww. j a va 2 s. c om*/ IModel collectionsModel = new LoadableDetachableModel() { @Override protected Object load() { RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); return collectionServices.list(); } }; ListView collectionsListView = new ListView("collections", collectionsModel) { @Override protected void populateItem(ListItem item) { RecordCollection collection = (RecordCollection) item.getModelObject(); Locale displayLocale = collection.getDisplayLocale(getLocale()); item.add(new Label("collection", collection.getTitle(displayLocale))); item.add(new SearchResultFieldListPanel("crudPanel", collection)); } }; add(collectionsListView); }