コード例 #1
0
  @Override
  public void removeConnector(ConnectorManager connectorManager, String connectorName) {
    String connectorType = getConnectorType(connectorManager, connectorName);

    Map<String, String> paramsMap = new HashMap<String, String>();
    paramsMap.put(ServletUtil.XMLTAG_CONNECTOR_NAME, connectorName);
    ConnectorManagerRequestUtils.sendGet(connectorManager, "/removeConnector", paramsMap);

    BackupServices backupServices = ConstellioSpringUtils.getBackupServices();
    if (backupServices.hasConfigBackup(connectorName, connectorType)) {
      backupServices.deleteConfigBackup(connectorName, connectorType);
    }
  }
コード例 #2
0
  @Override
  public void setSchedule(
      ConnectorManager connectorManager, String connectorName, Schedule schedule) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement(ServletUtil.XMLTAG_CONNECTOR_SCHEDULES);
    root.addElement(ServletUtil.XMLTAG_CONNECTOR_NAME).addText(connectorName);
    if (schedule.isDisabled()) {
      root.addElement(ServletUtil.XMLTAG_DISABLED).addText(Boolean.toString(schedule.isDisabled()));
    }
    root.addElement(ServletUtil.XMLTAG_LOAD).addText(Integer.toString(schedule.getLoad()));
    root.addElement(ServletUtil.XMLTAG_DELAY)
        .addText(Integer.toString(schedule.getRetryDelayMillis()));
    root.addElement(ServletUtil.XMLTAG_TIME_INTERVALS).addText(schedule.getTimeIntervalsAsString());
    ConnectorManagerRequestUtils.sendPost(connectorManager, "/setSchedule", document);

    String connectorType = getConnectorType(connectorManager, connectorName);
    BackupServices backupServices = ConstellioSpringUtils.getBackupServices();
    backupServices.backupConfig(connectorName, connectorType);
  }
コード例 #3
0
  private Element setConnectorConfig(
      ConnectorManager connectorManager,
      String connectorName,
      String connectorType,
      Map<String, String[]> requestParams,
      boolean update,
      Locale locale) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement(ServletUtil.XMLTAG_CONNECTOR_CONFIG);

    root.addElement(ServletUtil.QUERY_PARAM_LANG).addText(locale.getLanguage());
    root.addElement(ServletUtil.XMLTAG_CONNECTOR_NAME).addText(connectorName);
    root.addElement(ServletUtil.XMLTAG_CONNECTOR_TYPE).addText(connectorType);
    root.addElement(ServletUtil.XMLTAG_UPDATE_CONNECTOR).addText(Boolean.toString(update));

    for (String paramName : requestParams.keySet()) {
      if (!paramName.startsWith("wicket:")) {
        String[] paramValues = requestParams.get(paramName);
        for (String paramValue : paramValues) {
          Element paramElement = root.addElement(ServletUtil.XMLTAG_PARAMETERS);
          paramElement.addAttribute("name", paramName);
          paramElement.addAttribute("value", paramValue);
        }
      }
    }

    Element response =
        ConnectorManagerRequestUtils.sendPost(connectorManager, "/setConnectorConfig", document);
    Element statusIdElement = response.element(ServletUtil.XMLTAG_STATUSID);
    if (statusIdElement != null) {
      String statusId = statusIdElement.getTextTrim();
      if (!statusId.equals("" + ConnectorMessageCode.SUCCESS)) {
        return response;
      } else {
        BackupServices backupServices = ConstellioSpringUtils.getBackupServices();
        backupServices.backupConfig(connectorName, connectorType);
        return null;
      }
    } else {
      return null;
    }
  }
コード例 #4
0
  @Override
  public void synchronizeWithDatabase(ConnectorManager connectorManager) {
    ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices();

    // Add missing connector types
    List<String> connectorTypeNames = getConnectorTypes(connectorManager);
    for (String connectorTypeName : connectorTypeNames) {
      ConnectorType connectorType = connectorTypeServices.get(connectorTypeName);
      if (connectorType == null) {
        connectorType = new ConnectorType();
        connectorType.setName(connectorTypeName);

        File connectorsDir = ConstellioSpringUtils.getGoogleConnectorsDir();
        File connectorTypeDir = new File(connectorsDir, connectorType.getName());

        File iconFile = new File(connectorTypeDir, "icon.gif");
        if (iconFile.exists()) {
          try {
            byte[] iconBytes = FileUtils.readFileToByteArray(iconFile);
            connectorType.setIconFileContent(iconBytes);
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
        }

        File connectorTypeMetaXmlFile = new File(connectorTypeDir, "connectorTypeMeta.xml");
        if (connectorTypeMetaXmlFile.exists()) {
          String path = connectorTypeMetaXmlFile.toURI().toString();
          BeanFactory connectorTypeMeta = new FileSystemXmlApplicationContext(path);
          if (connectorTypeMeta.containsBean("searchResultPanelClassName")) {
            String searchResultPanelClassName =
                (String) connectorTypeMeta.getBean("searchResultPanelClassName");
            connectorType.setSearchResultPanelClassName(searchResultPanelClassName);
          }
          if (connectorTypeMeta.containsBean("initInstanceHandlerClassName")) {
            String initInstancePluginClassName =
                (String) connectorTypeMeta.getBean("initInstanceHandlerClassName");
            connectorType.setInitInstanceHandlerClassName(initInstancePluginClassName);
          }
        }

        connectorType.setConnectorManager(connectorManager);
        connectorTypeServices.makePersistent(connectorType);
      }
    }

    // Remove deleted connector types
    List<ConnectorType> dbConnectorType = connectorTypeServices.list();
    for (ConnectorType connectorType : dbConnectorType) {
      if (!connectorTypeNames.contains(connectorType.getName())) {
        connectorTypeServices.makeTransient(connectorType);
      }
    }

    ConnectorInstanceServices connectorInstanceServices =
        ConstellioSpringUtils.getConnectorInstanceServices();
    BackupServices backupServices = ConstellioSpringUtils.getBackupServices();
    List<ConnectorInstance> connectorInstances = connectorInstanceServices.list();
    for (ConnectorInstance connectorInstance : connectorInstances) {
      String connectorName = connectorInstance.getName();
      String connectorTypeName = connectorInstance.getConnectorType().getName();
      boolean existingConnector = isExistingConnector(connectorManager, connectorName);
      boolean hasConfigBackup = backupServices.hasConfigBackup(connectorName, connectorTypeName);
      if (!existingConnector && hasConfigBackup) {
        backupServices.restoreConfigBackup(connectorName, connectorTypeName);
      } else if (existingConnector && !hasConfigBackup) {
        backupServices.backupConfig(connectorName, connectorTypeName);
      }
    }
  }