org.springframework.data.annotation.LastModifiedDate Java Examples

The following examples show how to use org.springframework.data.annotation.LastModifiedDate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappingAuditableBeanWrapperFactory.java    From spring-data-mybatis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link MappingAuditingMetadata} instance from the given
 * {@link PersistentEntity}.
 */
public <P> MappingAuditingMetadata(
		MappingContext<?, ? extends PersistentProperty<?>> context,
		Class<?> type) {

	Assert.notNull(type, "Type must not be null!");

	this.createdByPaths = context.findPersistentPropertyPaths(type,
			withAnnotation(CreatedBy.class,
					org.springframework.data.mybatis.annotation.CreatedBy.class));
	this.createdDatePaths = context.findPersistentPropertyPaths(type,
			withAnnotation(CreatedDate.class,
					org.springframework.data.mybatis.annotation.CreatedDate.class));
	this.lastModifiedByPaths = context.findPersistentPropertyPaths(type,
			withAnnotation(LastModifiedBy.class,
					org.springframework.data.mybatis.annotation.LastModifiedBy.class));
	this.lastModifiedDatePaths = context.findPersistentPropertyPaths(type,
			withAnnotation(LastModifiedDate.class,
					org.springframework.data.mybatis.annotation.LastModifiedDate.class));

	this.isAuditable = Lazy.of( //
			() -> Arrays
					.asList(createdByPaths, createdDatePaths, lastModifiedByPaths,
							lastModifiedDatePaths) //
					.stream() //
					.anyMatch(it -> !it.isEmpty())//
	);
}
 
Example #2
Source File: ContentPropertyRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@StoreType("contentstore")
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.DELETE)
@ResponseBody
public ResponseEntity<?> deleteContent(@RequestHeader HttpHeaders headers,
									   @PathVariable String repository,
									   @PathVariable String id,
									   @PathVariable String contentProperty,
									   @PathVariable String contentId)
		throws HttpRequestMethodNotSupportedException {

	Object domainObj = findOne(repositories, repository, id);

	String etag = (BeanUtils.getFieldWithAnnotation(domainObj, Version.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, Version.class).toString() : null);
	Object lastModifiedDate = (BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) : null);
	HeaderUtils.evaluateHeaderConditions(headers, etag, lastModifiedDate);

	PersistentProperty<?> property = this.getContentPropertyDefinition(
			repositories.getPersistentEntity(domainObj.getClass()), contentProperty);

	Object contentPropertyValue = getContentProperty(domainObj, property, contentId);

	Class<?> contentEntityClass = ContentPropertyUtils.getContentPropertyType(property);

	ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, contentEntityClass);

	info.getImpementation().unsetContent(contentPropertyValue);

	// remove the content property reference from the data object
	// setContentProperty(domainObj, property, contentId, null);

	save(repositories, domainObj);

	return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
 
Example #3
Source File: ContentPropertyRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
private void replaceContentInternal(HttpHeaders headers, Repositories repositories,
		ContentStoreService stores, String repository, String id,
		String contentProperty, String contentId, String mimeType,
		String originalFileName, InputStream stream)
		throws HttpRequestMethodNotSupportedException {

	Object domainObj = findOne(repositories, repository, id);

	String etag = (BeanUtils.getFieldWithAnnotation(domainObj, Version.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, Version.class).toString() : null);
	Object lastModifiedDate = (BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) : null);
	HeaderUtils.evaluateHeaderConditions(headers, etag, lastModifiedDate);

	PersistentProperty<?> property = this.getContentPropertyDefinition(repositories.getPersistentEntity(domainObj.getClass()), contentProperty);

	Object contentPropertyValue = this.getContentProperty(domainObj, property, contentId);

	if (BeanUtils.hasFieldWithAnnotation(contentPropertyValue, MimeType.class)) {
		BeanUtils.setFieldWithAnnotation(contentPropertyValue, MimeType.class,
				mimeType);
	}

	if (originalFileName != null && StringUtils.hasText(originalFileName)) {
		if (BeanUtils.hasFieldWithAnnotation(contentPropertyValue,
				OriginalFileName.class)) {
			BeanUtils.setFieldWithAnnotation(contentPropertyValue,
					OriginalFileName.class, originalFileName);
		}
	}

	Class<?> contentEntityClass = ContentPropertyUtils.getContentPropertyType(property);

	ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, contentEntityClass);

	info.getImpementation().setContent(contentPropertyValue, stream);

	save(repositories, domainObj);
}
 
Example #4
Source File: AbstractJpaBaseEntity.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@LastModifiedDate
public void setLastModifiedAt(final long lastModifiedAt) {

    if (isController()) {
        return;
    }

    this.lastModifiedAt = lastModifiedAt;
}
 
Example #5
Source File: ContentEntityRestController.java    From spring-content with Apache License 2.0 4 votes vote down vote up
protected void handleMultipart(HttpServletRequest request, HttpServletResponse response, HttpHeaders headers, String store, String id, InputStream content, MediaType mimeType, String originalFilename)
		throws HttpRequestMethodNotSupportedException, IOException {

	ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, store);

	if (info == null) {
		throw new IllegalArgumentException(
				String.format("Store for path %s not found", store));
	}

	Object domainObj = findOne(repositories, info.getDomainObjectClass(), id);

	String etag = (BeanUtils.getFieldWithAnnotation(domainObj, Version.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, Version.class).toString() : null);
	Object lastModifiedDate = (BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) : null);
	HeaderUtils.evaluateHeaderConditions(headers, etag, lastModifiedDate);

	boolean isNew = true;
	if (BeanUtils.hasFieldWithAnnotation(domainObj, ContentId.class)) {
		isNew = (BeanUtils.getFieldWithAnnotation(domainObj, ContentId.class) == null);
	}

	if (BeanUtils.hasFieldWithAnnotation(domainObj, MimeType.class)) {
		BeanUtils.setFieldWithAnnotation(domainObj, MimeType.class, mimeType.toString());
	}

	if (originalFilename != null && StringUtils.hasText(originalFilename)) {
		if (BeanUtils.hasFieldWithAnnotation(domainObj, OriginalFileName.class)) {
			BeanUtils.setFieldWithAnnotation(domainObj, OriginalFileName.class, originalFilename);
		}
	}

	domainObj = info.getImpementation().setContent(domainObj, content);

	save(repositories, domainObj);

	if (isNew) {
		response.setStatus(HttpStatus.CREATED.value());
	}
	else {
		response.setStatus(HttpStatus.OK.value());
	}
}
 
Example #6
Source File: CmisTypeDefinitionFactoryBean.java    From spring-content with Apache License 2.0 4 votes vote down vote up
protected void addBasePropertyDefinitions(MutableTypeDefinition type, Class<?> entityClazz, CmisVersion cmisVersion, boolean inherited) {
	Field cmisNameField = BeanUtils.findFieldWithAnnotation(entityClazz, CmisName.class);
	if (cmisNameField != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:name", "Name", "Name", propertyType(cmisNameField), cardinality(cmisNameField), updatability(entityClazz, cmisNameField), inherited, true, false, false));
	}
	if (cmisVersion != CmisVersion.CMIS_1_0) {
		Field cmisDescField = BeanUtils.findFieldWithAnnotation(entityClazz, CmisDescription.class);
		if (cmisDescField != null) {
			type.addPropertyDefinition(this.createPropertyDefinition("cmis:description", "Description", "Description", propertyType(cmisDescField), cardinality(cmisDescField), updatability(entityClazz, cmisDescField), inherited, false, false, false));
		}
	}

	Field idField = BeanUtils.findFieldWithAnnotation(entityClazz, Id.class);
	if (idField == null) {
		idField = BeanUtils.findFieldWithAnnotation(entityClazz, org.springframework.data.annotation.Id.class);
	}
	if (idField != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:objectId", "Object Id", "Object Id", PropertyType.ID, cardinality(idField), Updatability.READONLY, inherited, false, false, false));
	}

	type.addPropertyDefinition(this.createPropertyDefinition("cmis:baseTypeId", "Base Type Id", "Base Type Id", PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, inherited, false, false, false));
	type.addPropertyDefinition(this.createPropertyDefinition("cmis:objectTypeId", "Object Type Id", "Object Type Id", PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, inherited, true, false, false));
	if (cmisVersion != CmisVersion.CMIS_1_0) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:secondaryObjectTypeIds", "Secondary Type Ids", "Secondary Type Ids", PropertyType.ID, Cardinality.MULTI, Updatability.READONLY, inherited, false, false, false));
	}

	Field field = BeanUtils.findFieldWithAnnotation(entityClazz, CreatedBy.class);
	if (field != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:createdBy", "Created By", "Created By", propertyType(field), cardinality(field), Updatability.READONLY, inherited, false, false, false));
	}
	field = BeanUtils.findFieldWithAnnotation(entityClazz, CreatedDate.class);
	if (field != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:creationDate", "Creation Date", "Creation Date", propertyType(field), cardinality(field), Updatability.READONLY, inherited, false, false, false));
	}
	field = BeanUtils.findFieldWithAnnotation(entityClazz, LastModifiedBy.class);
	if (field != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:lastModifiedBy", "Last Modified By", "Last Modified By", propertyType(field), cardinality(field), Updatability.READONLY, inherited, false, false, false));
	}
	field = BeanUtils.findFieldWithAnnotation(entityClazz, LastModifiedDate.class);
	if (field != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:lastModificationDate", "Last Modification Date", "Last Modification Date", propertyType(field), cardinality(field), Updatability.READONLY, inherited, false, false, false));
	}
	field = BeanUtils.findFieldWithAnnotation(entityClazz, Version.class);
	if (field != null) {
		type.addPropertyDefinition(this.createPropertyDefinition("cmis:changeToken", "Change Token", "Change Token", PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, inherited, false, false, false));
	}
}