List<FilmsView> filmsViews = new ArrayList<FilmsView>();
int nn = 1;
for (DBObject film : films)
{
FilmsView filmsView = new FilmsView();
filmsView.setOid(film.get("_id").toString());
logger.debug("Film _id: {}", filmsView.getOid());
filmsView.setNn(nn);
filmsView.setName(film.get("name").toString());
logger.debug("Film name: {}", filmsView.getName());
if (film.get("year") != null)
{
filmsView.setYear(((Number) film.get("year")).intValue());
logger.debug("Film year: {}", filmsView.getYear());
}
filmsView.setDescription("");
if (film.get("description") != null)
{
String description = film.get("description").toString();
description = description.replaceAll("\"", """);
filmsView.setDescription(description);
logger.debug("Film description: {}", description);
}
filmsView.setDirector("");
if (film.get("director") != null)
{
filmsView.setDirector(film.get("director").toString());
logger.debug("Film director: {}", filmsView.getDirector());
}
// Установку актеров в фильм будем делать на JS в момент клика по списку id. Все равно справочник актеров туда уходит.
filmsView.setActorIds(Arrays.asList(""));
if (film.get("actors") != null)
{
BasicDBList actorIds = (BasicDBList) film.get("actors");
List<String> a = new ArrayList<String>();
for (Object id : actorIds)
{
a.add(id.toString());
}
filmsView.setActorIds(a);
logger.debug("Film actors: {}", filmsView.getActorIds());
}
if (film.get("inserted_date") != null)
{
filmsView.setInsertedDate((Date) DifferentUtils.getShortDateFromString((String) film.get("inserted_date")));
logger.debug("Film inserted_date: {}", filmsView.getInserteDate());
}
filmsView.setSecondName("");
if (film.get("second_name") != null)
{
filmsView.setSecondName(film.get("second_name").toString());
logger.debug("Film second_name: {}", filmsView.getSecondName());
}
if (film.get("watched_dates") != null)
{
BasicDBList dates = (BasicDBList) film.get("watched_dates");
List<String> d = new ArrayList<String>();
for (Object date : dates.toArray())
{
d.add(date.toString());
}
filmsView.setWatchedDates(d);
logger.debug("Film watched_dates: {}", filmsView.getWatchedDates());
}
if (film.get("production") != null)
{
DBObject production = (DBObject) film.get("production");
List<ProductionView> p = new ArrayList<ProductionView>();
ProductionView pv = new ProductionView();
pv.setCountry(production.get("country").toString());
pv.setStudio(production.get("studio").toString());
p.add(pv);
filmsView.setProduction(p);
logger.debug("Film production: {}", filmsView.getProduction());
}
if (film.get("parts") != null)
{
PartsView partsView = new PartsView();
DBObject parts = (DBObject) film.get("parts");
partsView.setNumber(((Number) parts.get("number")).intValue());
if (parts.get("units") != null)
{
List<DBObject> units = (List<DBObject>) parts.get("units");
List<UnitView> unitViews = new ArrayList<UnitView>();
for (DBObject unit : units)
{
UnitView unitView = new UnitView();
unitView.setOnum(((Number) unit.get("onum")).intValue());
unitView.setName(unit.get("name").toString());
unitViews.add(unitView);
}
partsView.setUnits(unitViews);
}
filmsView.setParts(partsView);
logger.debug("Film parts: {}", filmsView.getParts());
}
if (film.get("type") != null)
{
filmsView.setType(FilmTypes.valueOf(film.get("type").toString().toUpperCase()));
}
filmsView.setJanr("");
if (film.get("janr") != null)
{
filmsView.setJanr(film.get("janr").toString());
logger.debug("Film janr: {}", filmsView.getJanr());
}
if (film.get("place") != null)
{
filmsView.setPlace(FilmPlaces.valueOf(film.get("place").toString().toUpperCase()));
}
if (film.get("premier") != null)
{
filmsView.setPremier(film.get("premier").toString());
logger.debug("Film premier: {}", filmsView.getPremier());
}
filmsViews.add(filmsView);
nn++;
}