/branches/ZCrawl/ZCrawlSources/src/org/zonales/crawlConfig/plugins/unpublishers/StandardUnpublisher.java
Java | 73 lines | 57 code | 7 blank | 9 comment | 7 complexity | 4dd34f63e121674cf2e934feaf77ed92 MD5 | raw file
Possible License(s): BSD-3-Clause
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package org.zonales.crawlConfig.plugins.unpublishers;
- import com.google.gson.Gson;
- import com.mongodb.MongoException;
- import java.net.HttpURLConnection;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.zonales.ZGram.ZGram;
- import org.zonales.ZGram.daos.ZGramDao;
- import org.zonales.crawlConfig.objets.State;
- import org.zonales.errors.ZMessage;
- import org.zonales.errors.ZMessages;
- import org.zonales.helpers.ConnHelper;
- /**
- *
- * @author juanma
- */
- public class StandardUnpublisher implements Unpublisher {
- @Override
- public String unpublish(ZGram zgram, String id, Properties props) {
- try {
- //Saco del Scheduler la extracción
- HttpURLConnection connection = ConnHelper.getURLConnection(props.getProperty("ZCrawlSchedulerURL") + "unschedulingJob?id=" + zgram.getId().get$oid(), Integer.valueOf(props.getProperty("timeout")));
- String zMessageJson;
- Gson zMessageGson = new Gson();
- ZMessage zmessage = new ZMessage();
- int code = connection.getResponseCode();
- Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Unscheduling Job - Código de respuesta: {0}", code);
- if (code == 200) {
- zMessageJson = ConnHelper.getStringFromInpurStream(connection.getInputStream());
- Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Unscheduling Job - Respuesta: {0}", zMessageJson);
- zmessage = zMessageGson.fromJson(zMessageJson, ZMessage.class);
- connection.disconnect();
- } else {
- Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error eliminando Job en el Scheduler");
- return ZMessages.ZSCHEDULER_CONN_ERROR.toString();
- }
- if (zmessage.getCod() == 100) {
- zgram.setEstado(State.UNPUBLISHED);
- ZGramDao zGramDao = new ZGramDao(props.getProperty("db_host"), Integer.valueOf(props.getProperty("db_port")), props.getProperty("db_name"));
- zGramDao.update(id, zgram);
- Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Extracción actualizada {0}", new Object[]{zgram});
- return ZMessages.SUCCESS.toString();
- } else {
- Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Error en Scheduler");
- return zmessage.toString();
- }
- } catch (MongoException ex) {
- Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Error actualizando extracción {0}: {1}", new Object[]{zgram, ex.getMessage()});
- return ZMessages.MONGODB_ERROR.toString();
- } catch (Exception ex) {
- StringBuilder stacktrace = new StringBuilder();
- for (StackTraceElement line : ex.getStackTrace()) {
- stacktrace.append(line.toString());
- stacktrace.append("\n");
- }
- Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
- "EXCEPCION: {0}\nTRACE: {1}", new Object[]{ex, stacktrace.toString()});
- return ZMessages.UNKNOWN_ERROR.toString();
- }
- }
- }