Skip to Content
author's profile photo Former Member
Former Member

Repository filter to populate VALIDFROM and VALIDTO

Hello all!

I am trying to write a repository filter which would extract the date value from the CREATED property, do some manipulations to that date, and put it into the VALIDFROM and VALIDTO properties.

I worked through the example tutorial: "Enforcing Custom Property Values" and I was successfully able to create a new property and populate it with a value.

The problem I am having is trying to populate the existing system properties. I can't seem to retrieve the CREATED property and I can't seem to populate the VALIDFROM and VALIDTO properties.

Any help I can get on this would be greatly appreciated!

Here is the snippet of code I am having trouble with:

public IPropertyMap filter() throws WcmException {
		
		Calendar createCalendar = Calendar.getInstance();
		Calendar validToCalendar = Calendar.getInstance();

		try {
			IPropertyMap propMap = this.predecessorFilter.filter();
			IPropertyName validFromProperty = new PropertyName("http://sapportals.com/xmlns/cm/tbp","VALIDFROM");
			IPropertyName validToProperty = new PropertyName("http://sapportals.com/xmlns/cm/tbp","VALIDTO");
			IPropertyName creationDatePropertyName = new PropertyName("http://sapportals.com/xmlns/cm","created");



			if (propMap.containsProperty(creationDatePropertyName)) {
				//gets the mutable representation of the property
				IMutableProperty mutableCreationDateProperty =
				propMap.get(creationDatePropertyName).getMutable();
				Date createDate = mutableCreationDateProperty.getDateValue();
				createCalendar.setTime(createDate);
			}
				Calendar deadLine = Calendar.getInstance();
				deadLine.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
				deadLine.set(Calendar.HOUR_OF_DAY, 17);
				deadLine.set(Calendar.MINUTE, 0);
				deadLine.set(Calendar.SECOND, 0);
				
				
				if(createCalendar.after(deadLine)){
					createCalendar.add(Calendar.WEEK_OF_YEAR, 1);
				}
				createCalendar.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
				
				
				validToCalendar.setTime(createCalendar.getTime());
				validToCalendar.add(Calendar.WEEK_OF_YEAR, 1);
				
				
			if (propMap.containsProperty(validFromProperty)) {
				IMutableProperty mutableProperty =
					propMap.get(validFromProperty).getMutable();
				mutableProperty.setDateValue(createCalendar.getTime());
				IMutablePropertyMap mutablePropertyMap = propMap.getMutable();
				mutablePropertyMap.put(mutableProperty);
			} else {
				System.err.println("PropertyFilter:  VALIDFROM property was not found.");
				IMutableProperty mutableProperty =
					new Property(validFromProperty, createCalendar.getTime())
						.getMutable();
				IMutablePropertyMap mutablePropertyMap = propMap.getMutable();
				mutablePropertyMap.put(mutableProperty);
			}

			if (propMap.containsProperty(validToProperty)) {
				System.err.println("PropertyFilter:  VALIDTO property was found.");
				IMutableProperty mutableProperty =
					propMap.get(validToProperty).getMutable();
				mutableProperty.setDateValue(validToCalendar.getTime());
				IMutablePropertyMap mutablePropertyMap = propMap.getMutable();
				mutablePropertyMap.put(mutableProperty);
				return mutablePropertyMap;
			} else {
				System.err.println("PropertyFilter:  VALIDTO property was not found.");
				IMutableProperty mutableProperty =
					new Property(validToProperty, validToCalendar.getTime())
						.getMutable();
				IMutablePropertyMap mutablePropertyMap = propMap.getMutable();
				mutablePropertyMap.put(mutableProperty);
				return mutablePropertyMap;
			}

		} catch (Exception e) {
			return this.predecessorFilter.filter();
		}
	}

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 07:02 PM

    Hi,

    Not sure, why you are unable to retrieve created property.

    The property should be cm_created and namespace , so check if you are using correct property id.

    Always post codes so that we can help you.

    Regards,

    Praveen Gudapati

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.