package include.converter;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import database.Configuration;
public class Converter {
/**
* Function converts window from database format to api format.
*
* @param dbw window in database format
* @return window in api format
*/
public village.webservice.user.Window windowToAPI (database.Window dbw){
village.webservice.user.Window apiw = new village.webservice.user.Window();
apiw.setBar(dbw.isMinimized());
apiw.setFullscreen(dbw.isMaximized());
apiw.setH(dbw.getPosition().getHeigth());
apiw.setW(dbw.getPosition().getLength());
apiw.setX(dbw.getPosition().getX());
apiw.setY(dbw.getPosition().getY());
apiw.setRid(dbw.getRid());
return apiw;
}
/**
* Function converts window from api format to database format and adds it to database.
*
* @param apiw window in api format
* @param login name of user
* @return window in database format
*/
public database.Window windowToDB(village.webservice.user.Window apiw, String login){
Configuration configuration = null;
try {
InitialContext ctx = new InitialContext();
configuration = (Configuration) ctx.lookup("ear3/CMPConfiguration/local");
} catch (NamingException e) {
e.printStackTrace();
}
int id = configuration.addWindow(apiw.getRid(), apiw.getX(), apiw.getY(), apiw.getW(), apiw.getH(), login);
return configuration.getWindow(id);
}
}