2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdcrests.notifications.rest.mapping;
23 import com.datastax.driver.core.utils.UUIDs;
24 import org.openecomp.core.utilities.json.JsonUtil;
25 import org.openecomp.sdc.notification.dao.types.NotificationEntity;
26 import org.openecomp.sdc.notification.dtos.NotificationsStatus;
27 import org.openecomp.sdcrests.mapping.MappingBase;
28 import org.openecomp.sdcrests.notifications.types.NotificationEntityDto;
29 import org.openecomp.sdcrests.notifications.types.NotificationsStatusDto;
31 import java.text.DateFormat;
32 import java.util.ArrayList;
33 import java.util.List;
36 public class MapNotificationsStatusToDto
37 extends MappingBase<NotificationsStatus, NotificationsStatusDto> {
39 private static final DateFormat formatter =
40 DateFormat.getDateTimeInstance(DateFormat.LONG,
44 public void doMapping(NotificationsStatus source, NotificationsStatusDto target) {
46 target.setLastScanned(source.getLastScanned());
47 target.setNewEntries(source.getNewEntries());
48 target.setEndOfPage(source.getEndOfPage());
49 target.setNumOfNotSeenNotifications(source.getNumOfNotSeenNotifications());
50 List<NotificationEntityDto> entityDtos = new ArrayList<>();
51 source.getNotifications()
52 .forEach(notification -> entityDtos.add(new NotificationEntityDto(notification.isRead(),
53 notification.getEventId(), notification.getEventType(),
54 JsonUtil.json2Object(notification.getEventAttributes(), Map.class),
55 extractDate(notification))));
56 target.setNotifications(entityDtos);
59 private String extractDate(NotificationEntity notification) {
60 return formatter.format(UUIDs.unixTimestamp