blob: 8bc650d8668f1e8a1f05a4d56d5f231a5da01f72 [file] [log] [blame]
/**
******************************************************************************
* Copyright © 2017-2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
package org.eclipse.openk.elogbook.controller;
import org.eclipse.openk.elogbook.common.BackendConfig;
import org.eclipse.openk.elogbook.common.JsonGeneratorBase;
import org.eclipse.openk.elogbook.communication.RestServiceWrapper;
import org.eclipse.openk.elogbook.exceptions.BtbException;
import org.eclipse.openk.elogbook.viewmodel.contactbasedata.ContactTupel;
import org.eclipse.openk.elogbook.viewmodel.contactbasedata.VwDetailedContact;
import org.eclipse.openk.elogbook.viewmodel.contactbasedata.VwDetailedContactPage;
import java.util.List;
import java.util.stream.Collectors;
public class ContactBaseDataManager {
private static final ContactBaseDataManager INSTANCE = new ContactBaseDataManager();
private ContactBaseDataManager() {
}
public static ContactBaseDataManager getInstance() {
return INSTANCE;
}
public List<ContactTupel> getUserContacts(String token) throws BtbException {
RestServiceWrapper restServiceWrapper = new RestServiceWrapper(BackendConfig.getInstance().getContactBaseDataApiUrl(), false);
String response = restServiceWrapper.performGetRequest("contacts?size=2000",token);
VwDetailedContactPage vwDetailedContactPage = JsonGeneratorBase.getGson().fromJson(response,
VwDetailedContactPage.class);
return vwDetailedContactPage.getContent().stream().map(this::mapFromViewObj ).collect(Collectors.toList());
}
private ContactTupel mapFromViewObj( VwDetailedContact vwDetailedContact ) {
String userName = vwDetailedContact.getName();
if (userName != null) {
userName = userName.replace("," ,"");
}
ContactTupel ct = new ContactTupel();
ct.setContactName(userName);
ct.setContactUuid(vwDetailedContact.getUuid());
return ct;
}
}