Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision meta data #137

Merged
merged 4 commits into from
Aug 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package com.devonfw.module.basic.common.api;

import java.util.Date;

/**
* This is the interface for the metadata associated with a
* {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity#getRevision() historic revision} of an
* {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity revisioned entity}.
*
* @since 3.2.0
*/
public interface RevisionMetadata {

/**
* This method gets the {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity#getRevision() revision
* number}.
*
* @return the revision number.
*/
Number getRevision();

/**
* This method gets the date when this revision was created (closed).
*
* @return the date of completion or {@code null} if the according entity is the latest revision.
*/
Date getDate();

/**
* This method gets the identifier (login) of the author who created this revision.
*
* @return the author. May be {@code null} (if committed outside user scope).
*/
String getAuthor();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.devonfw.module.basic.common.api;

import java.util.Date;

/**
* Implementation of {@link RevisionMetadata} as immutable type.
*/
public class RevisionMetadataType implements RevisionMetadata {

private final Number revision;

private final Date date;

private final String author;

/**
* The constructor.
*
* @param revision the {@link #getRevision() revision}.
* @param date the {@link #getDate() date}.
* @param author the {@link #getAuthor() author}.
*/
public RevisionMetadataType(Number revision, Date date, String author) {

this.revision = revision;
this.date = date;
this.author = author;
}

@Override
public Number getRevision() {

return this.revision;
}

@Override
public Date getDate() {

return this.date;
}

@Override
public String getAuthor() {

return this.author;
}

@Override
public String toString() {

return this.revision + "@" + this.date + " by " + this.author;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;

import com.devonfw.module.basic.common.api.RevisionMetadataType;
import com.devonfw.module.basic.common.api.entity.GenericEntity;
import com.devonfw.module.basic.common.api.reference.GenericIdRef;
import com.devonfw.module.basic.common.api.reference.Ref;
Expand Down Expand Up @@ -74,4 +75,20 @@ public static <E extends GenericEntity<?>, P extends E> void asEntities(Collecti
}
}

/**
* This is the newer implementation of RevisionMetadataType should be used with
* {@link com.devonfw.module.basic.common.api.RevisionMetadata}
*
* @param revEntity die {@link AdvancedRevisionEntity}.
* @return die Instanz von {@link RevisionMetadataType} bzw. {@code null} falls {@code revision} den Wert {@code null}
* hat.
*/
public static RevisionMetadataType asRevisionMetaData(AdvancedRevisionEntity revEntity) {

if (revEntity == null) {
return null;
}
return new RevisionMetadataType(revEntity.getId(), revEntity.getDate(), revEntity.getUserLogin());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,16 @@
* http://www.apache.org/licenses/LICENSE-2.0 */
package com.devonfw.module.jpa.dataaccess.api;

import java.util.Date;

/**
* This is the interface for the metadata associated with a
* {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity#getRevision() historic revision} of an
* {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity revisioned entity}.
* @deprecated use {@link com.devonfw.module.basic.common.api.RevisionMetadata} instead.
*
* This is the interface for the metadata associated with a
* {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity#getRevision() historic revision} of an
* {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity revisioned entity}.
*
* @since 3.0.0
*/
public interface RevisionMetadata {

/**
* This method gets the {@link com.devonfw.module.basic.common.api.entity.RevisionedEntity#getRevision() revision
* number}.
*
* @return the revision number.
*/
Number getRevision();

/**
* This method gets the date when this revision was created (closed).
*
* @return the date of completion or {@code null} if the according entity is the latest revision.
*/
Date getDate();

/**
* This method gets the identifier (login) of the author who created this revision.
*
* @return the author. May be {@code null} (if committed outside user scope).
*/
String getAuthor();
@Deprecated
public interface RevisionMetadata extends com.devonfw.module.basic.common.api.RevisionMetadata {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.util.Date;

/**
* Implementation of {@link RevisionMetadata} as immutable type.
* @deprecated use {@link com.devonfw.module.basic.common.api.RevisionMetadataType} instead.
*
* Implementation of {@link RevisionMetadata} as immutable type.
*/
@Deprecated
public class RevisionMetadataType implements RevisionMetadata {

private final Number revision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import javax.persistence.EntityManager;

import com.devonfw.module.basic.common.api.RevisionMetadata;
import com.devonfw.module.jpa.dataaccess.api.AdvancedRevisionEntity;
import com.devonfw.module.jpa.dataaccess.api.RevisionMetadata;

/**
* This is a lazy implementation of the {@link RevisionMetadata} interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javax.persistence.PersistenceException;

import com.devonfw.module.basic.common.api.RevisionMetadata;
import com.devonfw.module.basic.common.api.entity.RevisionedEntity;
import com.devonfw.module.basic.common.api.entity.RevisionedPersistenceEntity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;

import com.devonfw.module.basic.common.api.RevisionMetadata;
import com.devonfw.module.basic.common.api.entity.RevisionedPersistenceEntity;
import com.devonfw.module.jpa.dataaccess.api.GenericRevisionedDao;
import com.devonfw.module.jpa.dataaccess.api.RevisionMetadata;
import com.devonfw.module.jpa.dataaccess.impl.LazyRevisionMetadata;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.Serializable;
import java.util.List;

import com.devonfw.module.jpa.dataaccess.api.RevisionMetadata;
import com.devonfw.module.basic.common.api.RevisionMetadata;

/**
* {@link GenericRepository} with additional support for {@link org.hibernate.envers.Audited}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import org.hibernate.envers.AuditReaderFactory;
import org.springframework.data.jpa.repository.support.JpaEntityInformation;

import com.devonfw.module.basic.common.api.RevisionMetadata;
import com.devonfw.module.basic.common.api.entity.RevisionedEntity;
import com.devonfw.module.jpa.dataaccess.api.AdvancedRevisionEntity;
import com.devonfw.module.jpa.dataaccess.api.JpaHelper;
import com.devonfw.module.jpa.dataaccess.api.QueryUtil;
import com.devonfw.module.jpa.dataaccess.api.RevisionMetadata;
import com.devonfw.module.jpa.dataaccess.api.RevisionMetadataType;
import com.devonfw.module.jpa.dataaccess.api.data.GenericRevisionedRepository;
import com.devonfw.module.jpa.dataaccess.impl.LazyRevisionMetadata;
import com.querydsl.core.alias.Alias;
Expand All @@ -26,8 +26,8 @@
* Implementation of {@link GenericRevisionedRepository}.
*
* @param <E> generic type of the managed {@link #getEntityClass() entity}.
* @param <ID> generic type of the {@link com.devonfw.module.basic.common.api.entity.PersistenceEntity#getId() primary key}
* of the entity.
* @param <ID> generic type of the {@link com.devonfw.module.basic.common.api.entity.PersistenceEntity#getId() primary
* key} of the entity.
*
* @since 3.0.0
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ public List<RevisionMetadata> getRevisionHistoryMetadata(ID id, boolean lazy) {
QueryUtil.get().whereIn(query, Alias.$(rev.getId()), (List<Long>) revList);
query.orderBy(Alias.$(rev.getId()).asc());
List<AdvancedRevisionEntity> resultList = query.fetch();
return resultList.stream().map(x -> RevisionMetadataType.of(x)).collect(Collectors.toList());
return resultList.stream().map(x -> JpaHelper.asRevisionMetaData(x)).collect(Collectors.toList());
}
}

Expand All @@ -98,7 +98,7 @@ public RevisionMetadata getLastRevisionHistoryMetadata(ID id) {
if (revisionEntity == null) {
throw new IllegalStateException("Could not find AdvancedRevisionEntity for ID '" + id + "'.");
}
return RevisionMetadataType.of(revisionEntity);
return JpaHelper.asRevisionMetaData(revisionEntity);
}

}