Search in sources :

Example 1 with TimeStamp

use of de.micromata.opengis.kml.v_2_2_0.TimeStamp in project java-mapollage by trixon.

the class Operation method addPhoto.

private void addPhoto(File file) throws ImageProcessingException, IOException {
    mPhotoInfo = new PhotoInfo(file, mProfileSource.isIncludeNullCoordinate());
    try {
        mPhotoInfo.init();
    } catch (ImageProcessingException | IOException e) {
        if (mPhotoInfo.hasExif()) {
            mNumOfExif++;
        }
        throw e;
    }
    boolean hasLocation = false;
    if (mPhotoInfo.hasExif()) {
        mNumOfExif++;
        hasLocation = mPhotoInfo.hasGps() && !mPhotoInfo.isZeroCoordinate();
        if (hasLocation) {
            mNumOfGps++;
        }
    } else {
        throw new ImageProcessingException(String.format("E010 %s", file.getAbsolutePath()));
    }
    Date exifDate = mPhotoInfo.getDate();
    if (hasLocation && mProfilePath.isDrawPath()) {
        mLineNodes.add(new LineNode(exifDate, mPhotoInfo.getLat(), mPhotoInfo.getLon()));
    }
    if (hasLocation || mProfileSource.isIncludeNullCoordinate()) {
        Folder folder = getFolder(file, exifDate);
        String imageId = String.format("%08x", FileUtils.checksumCRC32(file));
        String styleNormalId = String.format("s_%s", imageId);
        String styleHighlightId = String.format("s_%s_hl", imageId);
        String styleMapId = String.format("m_%s", imageId);
        Style normalStyle = mDocument.createAndAddStyle().withId(styleNormalId);
        IconStyle normalIconStyle = normalStyle.createAndSetIconStyle().withScale(1.0);
        Style highlightStyle = mDocument.createAndAddStyle().withBalloonStyle(mBalloonStyle).withId(styleHighlightId);
        IconStyle highlightIconStyle = highlightStyle.createAndSetIconStyle().withScale(1.1);
        if (mProfilePlacemark.isSymbolAsPhoto()) {
            Icon icon = KmlFactory.createIcon().withHref(String.format("%s/%s.jpg", mThumbsDir.getName(), imageId));
            normalIconStyle.setIcon(icon);
            normalIconStyle.setScale(mProfilePlacemark.getScale());
            double highlightZoom = mProfilePlacemark.getZoom() * mProfilePlacemark.getScale();
            highlightIconStyle.setIcon(icon);
            highlightIconStyle.setScale(highlightZoom);
        }
        if (mProfilePlacemark.isSymbolAsPhoto() || mProfilePhoto.getReference() == ProfilePhoto.Reference.THUMBNAIL) {
            File thumbFile = new File(mThumbsDir, imageId + ".jpg");
            mFileThumbMap.put(file, thumbFile);
            if (Files.isWritable(thumbFile.getParentFile().toPath())) {
                mPhotoInfo.createThumbnail(thumbFile);
            } else {
                mListener.onOperationLog(String.format(mBundle.getString("insufficient_privileges"), mDestinationFile.getAbsolutePath()));
                Thread.currentThread().interrupt();
                return;
            }
        }
        mDocument.createAndAddStyleMap().withId(styleMapId).addToPair(KmlFactory.createPair().withKey(StyleState.NORMAL).withStyleUrl("#" + styleNormalId)).addToPair(KmlFactory.createPair().withKey(StyleState.HIGHLIGHT).withStyleUrl("#" + styleHighlightId));
        Placemark placemark = KmlFactory.createPlacemark().withName(getSafeXmlString(getPlacemarkName(file, exifDate))).withOpen(Boolean.TRUE).withStyleUrl("#" + styleMapId);
        String desc = getPlacemarkDescription(file, mPhotoInfo, exifDate);
        if (!StringUtils.isBlank(desc)) {
            placemark.setDescription(desc);
        }
        placemark.createAndSetPoint().addToCoordinates(mPhotoInfo.getLon(), mPhotoInfo.getLat(), 0F);
        if (mProfilePlacemark.isTimestamp()) {
            TimeStamp timeStamp = KmlFactory.createTimeStamp();
            timeStamp.setWhen(mTimeStampDateFormat.format(exifDate));
            placemark.setTimePrimitive(timeStamp);
        }
        folder.addToFeature(placemark);
        mNumOfPlacemarks++;
    }
    mListener.onOperationLog(file.getAbsolutePath());
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) IOException(java.io.IOException) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) ProfileFolder(se.trixon.mapollage.profile.ProfileFolder) Date(java.util.Date) TimeStamp(de.micromata.opengis.kml.v_2_2_0.TimeStamp) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) LineStyle(de.micromata.opengis.kml.v_2_2_0.LineStyle) PolyStyle(de.micromata.opengis.kml.v_2_2_0.PolyStyle) Style(de.micromata.opengis.kml.v_2_2_0.Style) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) BalloonStyle(de.micromata.opengis.kml.v_2_2_0.BalloonStyle) Icon(de.micromata.opengis.kml.v_2_2_0.Icon) File(java.io.File)

Example 2 with TimeStamp

use of de.micromata.opengis.kml.v_2_2_0.TimeStamp in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParserTest method testPerPeerHeaderIpv6.

@Test
public void testPerPeerHeaderIpv6() {
    final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(this.ipv6MsgWithDistinguishergBytes));
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    phBuilder.setType(PeerType.L3vpn);
    phBuilder.setPeerDistinguisher(new PeerDistinguisher(new RouteDistinguisher(new RdTwoOctetAs("0:" + RD))));
    phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
    phBuilder.setIpv4(false);
    phBuilder.setAddress(new IpAddress(new Ipv6Address("2001::1")));
    phBuilder.setAs(new AsNumber(168L));
    phBuilder.setBgpId(new Ipv4Address("1.1.1.2"));
    phBuilder.setTimestampSec(new Timestamp(0L));
    phBuilder.setTimestampMicro(new Timestamp(0L));
    assertEquals(phBuilder.build(), perHeader);
    final ByteBuf aggregator = Unpooled.buffer();
    phBuilder.setTimestampSec(null);
    phBuilder.setTimestampMicro(null);
    this.parser.serializePerPeerHeader(phBuilder.build(), aggregator);
    assertArrayEquals(this.ipv6MsgWithDistinguishergBytes, ByteArray.getAllBytes(aggregator));
}
Also used : RdTwoOctetAs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RdTwoOctetAs) PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) ByteBuf(io.netty.buffer.ByteBuf) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 3 with TimeStamp

use of de.micromata.opengis.kml.v_2_2_0.TimeStamp in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParser method parsePerPeerHeader.

protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
    Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    final PeerType peerType = PeerType.forValue(bytes.readByte());
    phBuilder.setType(peerType);
    final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
    phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
    phBuilder.setIpv4(!flags.get(V_FLAG_POS));
    switch(peerType) {
        case L3vpn:
            phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
            break;
        case Local:
            phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
            break;
        case Global:
        default:
            bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
            break;
    }
    if (phBuilder.isIpv4()) {
        bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        phBuilder.setAddress(new IpAddress(Ipv4Util.addressForByteBuf(bytes)));
    } else {
        phBuilder.setAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
    }
    phBuilder.setAs(new AsNumber(bytes.readUnsignedInt()));
    phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
    phBuilder.setTimestampSec(new Timestamp(bytes.readUnsignedInt()));
    phBuilder.setTimestampMicro(new Timestamp(bytes.readUnsignedInt()));
    return phBuilder.build();
}
Also used : PeerType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) BitArray(org.opendaylight.protocol.util.BitArray) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)

Example 4 with TimeStamp

use of de.micromata.opengis.kml.v_2_2_0.TimeStamp in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParserTest method testPerPeerHeader.

@Test
public void testPerPeerHeader() {
    final byte[] msgBytes = { (byte) 0x00, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // IPV4 192.168.1.1
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01, // AS 168
    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA8, // Peer BGP ID 1.1.1.1
    (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, // Timestamp
    (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 };
    final PeerHeader perHeader = AbstractBmpPerPeerMessageParser.parsePerPeerHeader(Unpooled.wrappedBuffer(msgBytes));
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    phBuilder.setType(PeerType.forValue(0));
    phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
    phBuilder.setIpv4(true);
    phBuilder.setAddress(new IpAddress(new Ipv4Address("192.168.1.1")));
    phBuilder.setAs(new AsNumber(168L));
    phBuilder.setBgpId(new Ipv4Address("1.1.1.1"));
    phBuilder.setTimestampSec(new Timestamp(16909060L));
    phBuilder.setTimestampMicro(new Timestamp(16909060L));
    assertEquals(perHeader, phBuilder.build());
    final ByteBuf aggregator = Unpooled.buffer();
    this.parser.serializePerPeerHeader(perHeader, aggregator);
    assertArrayEquals(msgBytes, ByteArray.getAllBytes(aggregator));
}
Also used : PeerHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) ByteBuf(io.netty.buffer.ByteBuf) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Aggregations

AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 Timestamp (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)3 PeerHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder)3 ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2 PeerDistinguisher (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher)2 PeerHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeader)2 ImageProcessingException (com.drew.imaging.ImageProcessingException)1 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)1 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)1 Icon (de.micromata.opengis.kml.v_2_2_0.Icon)1 IconStyle (de.micromata.opengis.kml.v_2_2_0.IconStyle)1 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)1 LineStyle (de.micromata.opengis.kml.v_2_2_0.LineStyle)1 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)1 PolyStyle (de.micromata.opengis.kml.v_2_2_0.PolyStyle)1 Style (de.micromata.opengis.kml.v_2_2_0.Style)1 TimeStamp (de.micromata.opengis.kml.v_2_2_0.TimeStamp)1