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.apache.commons.collections4.CollectionUtils;
25 import org.openecomp.core.utilities.json.JsonUtil;
26 import org.openecomp.sdc.notification.dao.types.NotificationEntity;
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 MapNotificationsToDto extends MappingBase<List<NotificationEntity>, NotificationsStatusDto> {
37 private static final DateFormat formatter =
38 DateFormat.getDateTimeInstance(DateFormat.LONG,
41 public void doMapping(List<NotificationEntity> source, NotificationsStatusDto target) {
42 List<NotificationEntityDto> entityDtos = new ArrayList<>();
43 if(CollectionUtils.isNotEmpty(source)) {
44 source.forEach(notification -> entityDtos.add(new NotificationEntityDto(notification.isRead(),
45 notification.getEventId(), notification.getEventType(), JsonUtil.json2Object(notification.getEventAttributes(), Map.class),
46 extractDate(notification))));
47 target.setNotifications(entityDtos);
48 target.setLastScanned(source.get(0).getEventId());
52 private String extractDate(NotificationEntity notification) {
53 return formatter.format(UUIDs.unixTimestamp