V2_0.java [src/java/m/rv/editsynonyms] Revision: default  Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API, and application suite.
 *
 * 2012-2022, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package m.rv.editsynonyms;

import com.jayway.jsonpath.ReadContext;
import csip.ModelDataService;
import csip.annotations.Description;
import csip.annotations.Name;
import csip.annotations.VersionInfo;
import edit.EditConnection;
import edit.EditQueries;
import javax.ws.rs.Path;

/**
 *
 */
@Name("Get ESID mapping")
@Description("Returns the mapping of an esIds to new ones.")
@VersionInfo("2.0")
@Path("d/esid/2.0")
public class V2_0 extends ModelDataService {

  @Override
  protected void doProcess() throws Exception {
    String[] esId = parameter().getStringArray("esId");
    String[] newEsIds = new String[esId.length];

    EditConnection edit = new EditConnection(LOG);
    ReadContext rc = edit.fetchAllSynonyms();

    for (int i = 0; i < esId.length; i++) {
      newEsIds[i] = EditQueries.getSynonymFor(rc, esId[i]);
    }

    results().put("new_esId", newEsIds);
  }

}